On Wednesday July 7 2010 05:53:59 jezhill wrote:
> Hi all,
>
> I've been experimenting with the NonUniformImage class. (Actually I want
> *uniform* pixel spacing, but I want the image x and y coordinates to have
> the correct *scaling* in the style of Matlab's image(x,y,C). The
> AxesImage class, created via pylab.imshow, didn't seem to offer that, so I
> landed on NonUniformImage, but if there's a better solution I'd be
> grateful for tips...)
>
>
> And here's the problem (or bug?): with my Python 2.5.4 and my matplotlib
> 1.0, I go and run the
> http://matplotlib.sourceforge.net/examples/pylab_examples/image_nonuniform.
> html gallery demo but I decide that I want the y axis reversed (as is
> common in image visualization). So I either call
> pylab.gca().invert_yaxis() at the end, or I change one of the lines that
> says
>
> ax.set_ylim(-4,4)
>
> to read
>
> ax.set_ylim(4,-4)
>
> which I believe is the approved method. However the result I get is
> non-sensical: no more image variation in the vertical direction. Can
> anyone tell me what, if anything, I'm doing wrong?
Hi jez,
I attached a slightly modified version of the image_nonuniform.py. I
additionally inverted the y-limits in the extent-kwarg and in the set_data of
the last example. I'm not sure why this is needed and if there is a better
solution to it, but at least for me it works.
Does anybody know why we have to invert all data concerning y-axis?
Kind regards,
Matthias
'''
This illustrates the NonUniformImage class, which still needs
an axes method interface; either a separate interface, or a
generalization of imshow.
'''
from matplotlib.pyplot import figure, show
import numpy as np
from matplotlib.image import NonUniformImage
interp='nearest'
x = np.linspace(-4, 4, 9)
x2 = x**3
y = np.linspace(-4, 4, 9)
#print 'Size %d points' % (len(x) * len(y))
z = np.sqrt(x[np.newaxis,:]**2 + y[:,np.newaxis]**2)
fig = figure()
fig.suptitle('NonUniformImage class')
ax = fig.add_subplot(221)
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4))
im.set_data(x, y, z)
ax.images.append(im)
ax.set_xlim(-4, 4)
ax.set_ylim(-4, 4)
ax.set_title(interp)
ax = fig.add_subplot(222)
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4))
im.set_data(x2, y, z)
ax.images.append(im)
ax.set_xlim(-64, 64)
ax.set_ylim(-4, 4)
ax.set_title(interp)
interp = 'bilinear'
ax = fig.add_subplot(223)
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4))
im.set_data(x, y, z)
ax.images.append(im)
ax.set_xlim(-4, 4)
ax.set_ylim(-4, 4)
ax.set_title(interp)
ax = fig.add_subplot(224)
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, 4, -4))
im.set_data(x2, y[::-1], z)
ax.images.append(im)
ax.set_xlim(-64, 64)
ax.set_ylim(4, -4)
ax.set_title(interp)
show()
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users