Hi all, and thanks for amazing matplotlib. I devellop my data processing / plotting software using glade, pygtk, scipy and matplotlib 0.83.2. I use the class library and I run into trouble with autoscaling. I expected that autoscale_view() function of axes class would do autoscaling. But if I update the data using set_data(), set_xdatat() or set_ydata() (of lines object) and I call autoscale_view() of the corresponding axes and then redraw the canvas, the scale is not changed and some data points are thus out of the picture. Do I miss or misunderstand something ? Regards, David
>>>>> "David" == David <dav...@fr...> writes: David> Hi all, and thanks for amazing matplotlib. I devellop my David> data processing / plotting software using glade, pygtk, David> scipy and matplotlib 0.83.2. David> I use the class library and I run into trouble with David> autoscaling. David> I expected that autoscale_view() function of axes class David> would do autoscaling. But if I update the data using David> set_data(), set_xdatat() or set_ydata() (of lines object) David> and I call autoscale_view() of the corresponding axes and David> then redraw the canvas, the scale is not changed and some David> data points are thus out of the picture. David> Do I miss or misunderstand something ? The axes keeps a copy of the "dataLim" and won't automatically know if you change the line's data. You need to call ax.update_datalim_numerix(x, y, ignore) where x and y are the numerix arrays you pass to line.set_data. If ignore is True, the previous data passed to the axes will be ignored in computing the new datalim. If False, the datalim will include the previous data and the current data you are passing it. After this, a call to ax.autoscale_view() should work as you expect. JDH
Hello, No actually it doesn't work exactly as I expected. I have different lines (at least two) that I would like to update and also hide/show and I expected that autoscaling will take all these aspects (updated data, hiden data) to scale the graph to all visibl= e data. The main problem is that old data limit is kept or totaly lost. The axes scaling doesn't seem to work with the list of lines, but is updated each time you add a line to the axes (as far as I can undestand from the source code). So the scale can only be increased but never decreased. Am I write or wrong ? Furthermore I use the sharey stuff that complicated a bit the story. So I don't think I can easelly do what I want using the axes class. Maybe I should calculate the scaling in my software and set the min/max v= alue. If one of you have another idea please let me know. Thanks for your help, David Selon John Hunter <jdh...@ac...>: > >>>>> "David" =3D=3D David <dav...@fr...> writes: > David> I use the class library and I run into trouble with > David> autoscaling. > > David> I expected that autoscale_view() function of axes class > David> would do autoscaling. But if I update the data using > David> set_data(), set_xdatat() or set_ydata() (of lines object) > David> and I call autoscale_view() of the corresponding axes and > David> then redraw the canvas, the scale is not changed and some > David> data points are thus out of the picture. > > The axes keeps a copy of the "dataLim" and won't automatically know if > you change the line's data. You need to call > > ax.update_datalim_numerix(x, y, ignore) > > where x and y are the numerix arrays you pass to line.set_data. > > If ignore is True, the previous data passed to the axes will be > ignored in computing the new datalim. If False, the datalim will > include the previous data and the current data you are passing it. > > After this, a call to > > ax.autoscale_view() > > should work as you expect. > > JDH >
david> I have different lines (at least two) that I would like to david> update and also hide/show and I expected that autoscaling david> will take all these aspects (updated data, hiden data) to david> scale the graph to all visible data. david> Furthermore I use the sharey stuff that complicated a bit the= story Thank you very much John. It works ! Here is the final version of the algorithm: line_list is the list of line >ignore =3D True >for line in (line_list): > if not line.get_visible(): continue > self.ax.dataLim.update_numerix( line.get_xdata(), > line.get_ydata(), > ignore ) > ignore =3D False >self.ax.autoscale_view() Note: we cannot use update_datalim_numerix() because "ignore" is not an a= rgument but using dataLim.update_numerix is ok. This version allows to avoid problem if the fist line is not visible (compared to your original version) Same function applied to the second axes which share the y axis and everything is perfect :-) What about adding this function to the axes class using the line list ava= ilable? Should give something like: def autoscale_visible_lines(self): ignore =3D True for line in (self.lines): if not line.get_visible(): continue self.dataLim.update_numerix( line.get_xdata(), line.get_ydata(), ignore ) ignore =3D False self.autoscale_view() Thanks for your help and your amazing matplotlib ! Best regards, David Selon John Hunter <jdh...@ac...>: > If you have a list of lines that you want to pass to the autoscaler, > and have it operate on that list only (ignoring previous settings) do > the following > > First update your line data and then create a list of lines that you > want to autoscale for. The ignore setting will be True for the first > line in the list which will cause it to ignore it's history. Thus the > datalim will be updated to bound only the lines in the list "lines" > > for i,line in enumerate(lines): > ignore =3D i=3D=3D0 > if not line.get_visible(): continue > x =3D asarray(line.get_xdata()) > y =3D asarray(line.get_ydata()) > ax.update_datalim_numerix(x, y, ignore) > ax.autoscale_view() > > You should be able to do this separately for each of your two axes > (even if they are sharing the x axes, their y axes is independent). > > If you are still having trouble after trying this, please post a > complete example. > > JDH >