Christoph Bersch
2011-02-08 09:05:30 UTC
Hi,
I'm trying to autoscale an AxesImage after having set new data with
set_data(). I thought, the way to do it is to use Axes.relim() followed
by Axes.autoscale_view(). Unfortunately, this does not work properly
both with version 0.99.3 and 1.0.1.
Consider the following example (adapted from the example
<http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html>):
import time
import numpy as np
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x, y = np.mgrid[0:100, 0:100]
img = ax.imshow(np.sin(0.05 * y))
def animate():
time.sleep(3)
x, y = np.mgrid[0:200, 0:200]
img.set_data(np.sin(0.05 * x))
# set_*lim works with v 0.99.3
ax.set_xlim(0, 200)
ax.set_ylim(0, 200)
# ax.relim()
# ax.autoscale_view()
fig.canvas.draw()
return False
import gobject
gobject.idle_add(animate)
plt.show()
I want the plot to show the 200x200 image after the update, with the
correct ticks showing. But what I get is the following:
Using set_xlim() and set_ylim() works, but only for version 0.99.3.
With version 1.0.1 the axes show a range of 200x200, and the new image
data is used, but the new 200x200 image is shrunk to a 100x100 region.
Using relim() and autoscale_view(), which is what I thought the correct
way to do it, also does not work:
With version 0.99.3 it does nothing, it does no autoscaling at all. With
version 1.0.1 the new image is shown completely, but the axes ticks
still show 0..100 instead of 0..200
Thanks for you help,
Christoph
I'm trying to autoscale an AxesImage after having set new data with
set_data(). I thought, the way to do it is to use Axes.relim() followed
by Axes.autoscale_view(). Unfortunately, this does not work properly
both with version 0.99.3 and 1.0.1.
Consider the following example (adapted from the example
<http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html>):
import time
import numpy as np
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x, y = np.mgrid[0:100, 0:100]
img = ax.imshow(np.sin(0.05 * y))
def animate():
time.sleep(3)
x, y = np.mgrid[0:200, 0:200]
img.set_data(np.sin(0.05 * x))
# set_*lim works with v 0.99.3
ax.set_xlim(0, 200)
ax.set_ylim(0, 200)
# ax.relim()
# ax.autoscale_view()
fig.canvas.draw()
return False
import gobject
gobject.idle_add(animate)
plt.show()
I want the plot to show the 200x200 image after the update, with the
correct ticks showing. But what I get is the following:
Using set_xlim() and set_ylim() works, but only for version 0.99.3.
With version 1.0.1 the axes show a range of 200x200, and the new image
data is used, but the new 200x200 image is shrunk to a 100x100 region.
Using relim() and autoscale_view(), which is what I thought the correct
way to do it, also does not work:
With version 0.99.3 it does nothing, it does no autoscaling at all. With
version 1.0.1 the new image is shown completely, but the axes ticks
still show 0..100 instead of 0..200
Thanks for you help,
Christoph