autoscale using class library

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

autoscale using class library

David-60
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



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: autoscale using class library

John Hunter-8
>>>>> "David" == David  <[hidden email]> 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


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: autoscale using class library

David-60
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 visible 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 value.

If one of you have another idea please let me know.

Thanks for your help,

David



Selon John Hunter <[hidden email]>:

> >>>>> "David" == David  <[hidden email]> 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
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: autoscale using class library

David-60
     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 = 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 :-)

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 <[hidden email]>:

> 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
>




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...