Issues with Affine2D transform

Hi,

I have been trying to use the Affine2D transformation with pcolor and contour, with no success. The following script and comments illustrates my problems:

matplotlib.use('Agg')
import matplotlib.pyplot as mpl
from matplotlib.transforms import Affine2D
import numpy as np

image = np.random.random((100,100))

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.pcolor(image, transform=Affine2D()) # Does not work - the image is not there!
fig.savefig('test1.png')

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.contour(image, transform=Affine2D()) # Ok, but transformation wouldn't change anything anyway
fig.savefig('test2.png')

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.contour(image, transform=Affine2D().scale(10.,10.)) # Does not work - the image is unchanged
fig.savefig('test3.png')

Is there a reason why transform doesn't work for contour and pcolor?

Thanks for any help,

Thomas

The get/set_transform on an artist (any artist really), is an internal implementation detail that transforms points from data space all the way to pixels. It's not really useful to the end user, unless you want to have very low-level control over plotting. If you want to change how data points are converted into physical plot space, you probably want to look at creating a custom scale or projection documented here instead:

  http://matplotlib.sourceforge.net/devel/add_new_projection.html

Additionally, we should probably make private and/or undocument get/set_transform, or at the very least make the docstring more explicit that it is an internal function.

Mike

Thomas Robitaille wrote:

Hi,

I have been trying to use the Affine2D transformation with pcolor and contour, with no success. The following script and comments illustrates my problems:

matplotlib.use('Agg')
import matplotlib.pyplot as mpl
from matplotlib.transforms import Affine2D
import numpy as np

image = np.random.random((100,100))

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.pcolor(image, transform=Affine2D()) # Does not work - the image is not there!
fig.savefig('test1.png')
  

The image is there, it's just in the lower left corner of the figure, outside of the axes.

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.contour(image, transform=Affine2D()) # Ok, but transformation wouldn't change anything anyway
fig.savefig('test2.png')
  
fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.contour(image, transform=Affine2D().scale(10.,10.)) # Does not work - the image is unchanged
fig.savefig('test3.png')
  

Contour ignores the standard transformation member -- again just an implementation detail.

Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Note that the transform is a transform to the canvas coordinate (in
pixel scale).

-JJ

···

On Mon, Apr 5, 2010 at 10:05 AM, Michael Droettboom <mdroe@...86...> wrote:

matplotlib.use('Agg')
import matplotlib.pyplot as mpl
from matplotlib.transforms import Affine2D
import numpy as np

image = np.random.random((100,100))

fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.pcolor(image, transform=Affine2D()) # Does not work - the image is not there!
fig.savefig('test1.png')

The image is there, it's just in the lower left corner of the figure,
outside of the axes.