Autoscale embedding in gtk + dynamical update of plot + Y log scale

Hi All,
I'm facing a weird problem while embedding in a gtk window made with
glade (dunno if this might be involved in the problem, but worth
noticing) + dynamical update of the plot.

What I'm doing is:

fig = Figure()
ax = fig.add_subplot(111)
line, = ax.plot([], [])

then using that reference to update the plot when user click on a button:

def update_graph(<params>):
    line_ref.set_data(np.array([L1, L2]))
    ax.set_yscale('log')
    fig_ref.canvas.draw()

Sadly, the graph embedded remains unchanged, if not for the Y labels &
ticks that changes because of the log scale.

The data is there, becase if I explicitly set the x/ylim then the data
are shown, but i'd like mpl to autoscale.

I've used several tentatives to make it works:

- ax.set_autoscale_on(True)
- ax.autoscale_view()

but none of them worked.

Do you know if there's something I can do to make that graph autoscale
at "set_data" time? can I force it somehow? if I can't do it handy, is
there a workaround to obtain the same effect?

Thanks in advance,

···

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Hi All,
I'd like to renew this request below.

I've worked-around this problem setting xlim/ylim (as min/max of the
relative axis) right before redraw the figure, but I'd like to know
for a more elegant solution.

Thanks in advance,
Sandro

···

On Sun, May 10, 2009 at 23:31, Sandro Tosi <morph@...10...> wrote:

Hi All,
I'm facing a weird problem while embedding in a gtk window made with
glade (dunno if this might be involved in the problem, but worth
noticing) + dynamical update of the plot.

What I'm doing is:

fig = Figure()
ax = fig.add_subplot(111)
line, = ax.plot(, )

then using that reference to update the plot when user click on a button:

def update_graph(<params>):
line_ref.set_data(np.array([L1, L2]))
ax.set_yscale('log')
fig_ref.canvas.draw()

Sadly, the graph embedded remains unchanged, if not for the Y labels &
ticks that changes because of the log scale.

The data is there, becase if I explicitly set the x/ylim then the data
are shown, but i'd like mpl to autoscale.

I've used several tentatives to make it works:

- ax.set_autoscale_on(True)
- ax.autoscale_view()

but none of them worked.

Do you know if there's something I can do to make that graph autoscale
at "set_data" time? can I force it somehow? if I can't do it handy, is
there a workaround to obtain the same effect?

Thanks in advance,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

If you change the data directly, and want mpl to autoscale, you need
to call ax.relim() before calling ax.autoscale_view(). mpl stores the
min/max of the data you add to it when you add the lines, rectangles,
etc to the figure. When you update the data directly, there is no
internal mechanism to notify the limits to update (we could add this
but haven't). So you must explicitly call relim, which tells mpl to
reinspect the data recalculate the limits. It might be a better
design to have each artist store its limits, updating them when data
is updated, and then having the container artists, eg the Axes, do a
union of the child bboxes. But this is not the design we have
currently.

Hope this helps,
JDH

JDH

···

On Tue, May 12, 2009 at 12:11 PM, Sandro Tosi <morph@...10...> wrote:

Hi All,
I'd like to renew this request below.

I've worked-around this problem setting xlim/ylim (as min/max of the
relative axis) right before redraw the figure, but I'd like to know
for a more elegant solution.

Thanks in advance,
Sandro

On Sun, May 10, 2009 at 23:31, Sandro Tosi <morph@...10...> wrote:

Hi All,
I'm facing a weird problem while embedding in a gtk window made with
glade (dunno if this might be involved in the problem, but worth
noticing) + dynamical update of the plot.

What I'm doing is:

fig = Figure()
ax = fig.add_subplot(111)
line, = ax.plot(, )

then using that reference to update the plot when user click on a button:

def update_graph(<params>):
   line_ref.set_data(np.array([L1, L2]))
   ax.set_yscale('log')
   fig_ref.canvas.draw()

Sadly, the graph embedded remains unchanged, if not for the Y labels &
ticks that changes because of the log scale.

The data is there, becase if I explicitly set the x/ylim then the data
are shown, but i'd like mpl to autoscale.

I've used several tentatives to make it works:

- ax.set_autoscale_on(True)
- ax.autoscale_view()

but none of them worked.

Hi John,

mpl_glade1.png

mpl_glade2.png

···

On Tue, May 12, 2009 at 22:55, John Hunter <jdh2358@...287...> wrote:

If you change the data directly, and want mpl to autoscale, you need
to call ax.relim() before calling ax.autoscale_view(). mpl stores the
min/max of the data you add to it when you add the lines, rectangles,
etc to the figure. When you update the data directly, there is no
internal mechanism to notify the limits to update (we could add this
but haven't). So you must explicitly call relim, which tells mpl to
reinspect the data recalculate the limits. It might be a better
design to have each artist store its limits, updating them when data
is updated, and then having the container artists, eg the Axes, do a
union of the child bboxes. But this is not the design we have
currently.

Ahhh, relim() - that's what I was missing! :slight_smile:

Well, now that I've tried with relim(), I don't know it the result is
better or not :S I'm attaching the screenshots here for comments (if
there's any): 1 is with xlim/ylim set to max of datapoints, 2 is with
relim and ax.autoscale_view()

Cheers,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi