autoscale using class library

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 visible data.
     > 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 = 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 = False
    >self.ax.autoscale_view()

Note: we cannot use update_datalim_numerix() because "ignore" is not an argument
      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 :slight_smile:

What about adding this function to the axes class using the line list available?
Should give something like:

  def autoscale_visible_lines(self):
    ignore = True
    for line in (self.lines):
       if not line.get_visible(): continue
       self.dataLim.update_numerix( line.get_xdata(),
                                    line.get_ydata(),
                                    ignore )
       ignore = False
    self.autoscale_view()

Thanks for your help and your amazing matplotlib !

Best regards,

David

Selon John Hunter <jdhunter@...4...>:

···

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 = i==0
   if not line.get_visible(): continue
   x = asarray(line.get_xdata())
   y = 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