On Sat, Feb 27, 2010 at 11:04 PM, Massimo Di Stefano
<massimodisa...@yahoo.it> wrote:
> Hi All,
>
> i've data store in a multydimension numpy.array,
> it is composed by 3 MxN normalized (0 - 1) array
> but tring to display it using "imshow" i get an error,
> " TypeError: Invalid dimensions for image data "
> please can you help me to fix this problem ?
> my data is :
> In [120]: len(dd[0])
> Out[120]: 3
>
> In [121]: dd[0].shape
> Out[121]: (3, 2058, 2607)
>
> In [122]: matplotlib.pyplot.imshow(dd[0])
> ------------------------------------------------------------
> Traceback (most recent call last):
>   File "<ipython console>", line 1, in <module>
>   File "/Library/Python/2.6/site-packages/matplotlib/pyplot.py", line 2035,
> in imshow
>     ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax,
> origin, extent, shape, filternorm, filterrad, imlim, resample, url,
> **kwargs)
>   File "/Library/Python/2.6/site-packages/matplotlib/axes.py", line 6272, in
> imshow
>     im.set_data(X)
>   File "/Library/Python/2.6/site-packages/matplotlib/image.py", line 372, in
> set_data
>     raise TypeError("Invalid dimensions for image data")
> TypeError: Invalid dimensions for image data

Your image data is 3xMxN, but according to the imshow docstring:

" MxNx3 -- RGB (float or uint8 array)"

So a quick way is to use the transpose do:

matplotlib.pyplot.imshow(dd[0].transpose())

However, this will rotate the image (result will have N rows and M
columns), if you're expecting it to have M rows and N columns. In that
case, you need to "roll" the axis to the end, which will end up with a
3xMxN array:

>>>dd[0].shape
(3, 2058, 2607)
>>>data2 = np.rollaxis(dd[0], 0, 3)
>>>data2.shape
(2058, 2607, 3)
plt.imshow(data2)

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to