[Prev] Thread [Next]  |  [Prev] Date [Next]

[Matplotlib-users] Autoscale AxesImage after using set_data() Christoph Bersch Tue Feb 08 02:00:15 2011


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 

import time
import numpy as np
import matplotlib

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():
      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()
      return False

import gobject

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,

The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
Matplotlib-users mailing list