Dear developers,

the following example shows a somewhat unexpected behaviour of the 
get_xlim() method of an axis object: it returns a view to the internal 
data structure used to store the data limits. Because of this saving and 
restoring the data limits failed in this example (I am using matplotlib 
0.98.3):

from pylab import *
plot([0,1], [0,1]) #create some plot
ax = gca() #keep reference to axis
#after some time, I want to change the plot content, but keep the data 
limits
xlimits = ax.get_xlim() #save limits
print xlimits
ax.clear()            #first clear axis, then
plot([1,2], [1,2])    #create new plot content
ax.set_xlim(xlimits)  #does _not_ restore old limits
print xlimits         #since saved xlimits also changed

Now I know that I have to use

xlimits = ax.get_xlim().copy()

if I want to save the data limits.

Is this really an intended behaviour? Wouldn't it be better if 
get_xlim() already returns a copy? Or could at least the documentation 
be updated to mention this pitfall?

Gregor



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to