[Matplotlib-users] using STIX sans serif fonts for non-mathtext
Hi, I am a fan of the STIX sans serif typeface for mathtext, but I was wondering if it was possible to use this typeface for non-mathtext text as well. My main use for this is ticklabels, which seem to render in the non-mathtext font no matter what I do. I have tried using ax.xaxis.set_major_formatter(P.ScalarFormatter(useMathText=True)) to force the (scalar) major ticks to use mathtext and thus stixsans, but this does not work. Am I doing something wrong here? A better solution (for me) would be to use STIX sans serif faces as the regular font, ie something like rcParams["font.sans-serif"] = 'stixsans' I know this is possible for serif fonts, and I know that a post to the list back in 2008 noted that it was not (at that time) possible for sans-serifs. I am curious to know if there has been any progress on allowing STIX sans-serifs in non-mathtext text. thanks, Jeff Oishi -- Download Intel® 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
Re: [Matplotlib-users] mplot3d stays?
http://www.friedrichromstedt.org/python/pyclip/a01.Zerteilung.pdf (It's unfortunately in german, but the graphics are self-explaining) A school mate working together with me on the project has worked that out. H = number of corners of the front triangle lying inside of the back triangle V = number of corners of the back triangle lying inside of the front triangle S = number of the collinear edges of the two triangles Z = number of intersection points of the two tringles' edges, minus the number of those occuring because of collinear edges. Red: front triangle Black: back triangle Green: subdivision lines in the back triangle. I will check my implementation in C++ today. I will maybe need some advice in making a Python module out of it. Friedrich -- Download Intel® 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
[Matplotlib-users] Optimal positioning of text
Hi All, I am trying to visualize some more text in an already rather crowded 2D plot. As this new information I want to display is optional (it depends on a use choice) but possibly very useful as information, I would like to add it as text inside my plot, and possibly to add it in a "smart" way (i.e., with minimum or no overlapping between this new text and the rest of the plot, like legend does with loc=0). Now, I have tried to steal the code from legend.py but I am not getting anywhere, also because I am mixing display coordinates, data coordinates and wx.DC text extents and I am getting crazy :-( This is the code I have so far: def PositionAnnotation(self, dc, label, dash, x, y): """ Position a matplotlib text instance without overlapping with the rest of the data. :param `dc`: an instance of wx.ClientDC; :param `label`: the label to display (2 lines of text); :param `dash`: the actual TextWithDash matplotlib class to position :param `x`: a list of possible x location (this is fixed) :param `y`: a list of possible y location (this is fixed) """ # Stolen from legend.py lines = [] # Here I work with display coordinates (!) for handle in self.leftaxis.lines: path = handle.get_path() trans = handle.get_transform() tpath = trans.transform_path(path) lines.append(tpath) # End of stolen from legend.py # Here I work with screen/character coordinates (!) width, height, dummy = dc.GetMultiLineTextExtent(label) candidates = [] for l, b in zip(x, y): # And here I work with data coordinates (!) dashBox = Bbox.from_bounds(l, b, width+5, height+5) badness = 0 for line in lines: if line.intersects_bbox(dashBox): badness += 1 ox, oy = l, b if badness == 0: return ox, oy candidates.append((badness, (l, b))) # Stolen from legend.py # rather than use min() or list.sort(), do this so that we are assured # that in the case of two equal badnesses, the one first considered is # returned. # NOTE: list.sort() is stable.But leave as it is for now. -JJL minCandidate = candidates[0] for candidate in candidates: if candidate[0] < minCandidate[0]: minCandidate = candidate ox, oy = minCandidate[1] return ox, oy This code is not doing anything useful as I always get a badness of 0, although I can see that the new text overlaps quite a lot of other artists. Does anyone have some suggestion on how to improve the code? Thank you in advance. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ http://thedoomedcity.blogspot.com/ -- Download Intel® 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
Re: [Matplotlib-users] imshow size limitations?
Hi, folks! I'm again encountering the problem - imshow generating a MemoryError exception trying to image a very large array - discussed in this thread I started almost a year and a half ago. Question 1) has anything changed in MPL in that time interval which would provide an "easy" solution? Question 2) is there some way I can add pieces of the array incrementally to the image into their proper place, i.e., modify the following code: ax.imshow(image[0:ny/2+1, 0:nx/2+1]) # upper left corner of image ax.hold(True) ax.imshow(argW[ny/2+1:-1, 0:nx/2+1]) # lower left corner of image ax.imshow(argW[0:ny/2+1, nx/2+1:-1]) # upper right corner of image ax.imshow(argW[ny/2+1:-1, nx/2+1:-1]) # lower right corner of image so that each subsequent imshow doesn't cover up the previous imshow and is placed in the right place relative to each of the other pieces? Question 3) Would such incremental addition work to get around the memory limit, or does the fact (if the following statement is in fact correct) that eventually the entire too-large image needs to be handled doom this strategy to failure? Question 4) would I have this problem if I was running 64 bit (i.e., OS, as well as 64 bit builds of Python, numpy, MPL, etc.), i.e., is it most likely a memory addressing problem? Question 5) can anyone suggest any other work-around(s)? Thanks! DG On Sat, Sep 6, 2008 at 4:00 PM, David Goldsmith wrote: > Ah, Ich verstehe now. I'll try RGBA-ing it; in the meantime, let me know > if the colormapping conversion gets changed to 32 bit. Thanks again! > > DG > > --- On Sat, 9/6/08, Eric Firing wrote: > > > From: Eric Firing > > Subject: Re: [Matplotlib-users] imshow size limitations? > > To: d_l_goldsm...@yahoo.com > > Cc: matplotlib-users@lists.sourceforge.net > > Date: Saturday, September 6, 2008, 3:13 PM > > David Goldsmith wrote: > > > Thanks, Eric! > > > > > > --- On Sat, 9/6/08, Eric Firing > > wrote: > > > > > > -- snip OP -- > > > > > >> It looks to me like you simply ran out of > > memory--this is > > >> not an imshow > > >> problem as such. Your array is about 1e8 > > elements, and as > > >> floats that > > >> would be close to a GB--just for that array alone. > > Do you > > > > > > Well, I anticipated that, so I do initialize the > > storage for the numpy array as numpy.uint8 and have > > confirmed that the data in the array returned by the > > function which creates it remains numpy.uint8, so it should > > "only" be ~100MB (indeed, the .na file into which > > I tofile it is 85,430 KB, just as it should be for a 10800 x > > 8100 array of uint8 elements). And the ax.imshow statement > > doesn't (directly) cause the crash (but I don't know > > that it isn't making either a float copy or an in-place > > conversion of the array). So, AFAIK, right up until the > > statement: > > > > > > canvas.print_figure('HiResHex') > > > > > > the data being imaged are all numpy.uint8 type. > > > > Yes, but it looks to me like they are still getting > > color-mapped, and > > this requires conversion to numpy.float. This may be a bad > > aspect of > > the mpl design, but it is quite deeply embedded. I suspect > > the best we > > could do would be to use float32 instead of float64; > > certainly for color > > mapping one does not need 64 bits. > > > > Using numpy.uint8 helps only if you are specifying RGBA > > directly, > > bypassing the colormapping. > > > > > > > >> really need > > >> all that resolution? > > > > > > Well, there's the rub: I fancy myself a fractal > > "artist" and I have > > > access to an HP DesignJet 500ps plotter with a maximum > > resolution of > > > 1200 x 600 dpi. For the size images I'm trying to > > make (I'm hoping to go > > > even bigger than 36" x 27", but I figured > > that as a good starting point) > > > even I regard _that_ resolution as too much - I was > > thinking of 300 x > > > 300 dpi (which is its "normal" resolution) > > as certainly worthy of giving > > > a try. :-) > > > > >> If you do, you will probably have to > > >> get a much > > >> more capable machine. > > > > > > Possible, but I was hoping to generate at least one > > "proof" first to determine how hard I'd need > > to try. > > > > > >> Otherwise, you need to knock down > > >> the size of > > >> that array before trying to plot or otherwise > > manipulate > > >> it. > > > > > > Forgive me, but I'd like a more detailed > > explanation as to why: I > > > have > > > ample (~35 GB, just on my built-in disc, much more > > than that on external > > > discs) harddisc space - isn't there some way to > > leverage that? > > > > I don't know enough about virtual memory > > implementations--especially on > > Win or Mac--to say. In practice, I suspect you would find > > that as soon > > as you are doing major swapping during a calculation, you > > will thrash > > the disk until you run out of patience. > > > > > > >> With respect to imshow, probably you can get it to > > handle > > >> larger images > > > > > > Ag
Re: [Matplotlib-users] TeX and the PDF Backend
I believe it is not just the size of font but the font itself should match. Depending on your setting, the tex file generated by matplotlib include preambles related with font setting. For example, below is mine. \documentclass{article} \usepackage{type1cm} \renewcommand{\rmdefault}{pnc} \usepackage{helvet} \usepackage{courier} \usepackage{textcomp} \usepackage{ucs} \usepackage[utf8x]{inputenc} And of course, the output is different from the output without these preambles. So when you say, On Fri, Feb 26, 2010 at 5:09 AM, Freddie Witherden wrote: > Does anyone know what might be causing this? The document font sizes are the > same and I tried to match the LaTeX file as closely as possible to the one > used > internally by matplotlib. > Did you match those font preambles also? Also, is it just the pdf backend? What about other backend? Regards, -JJ -- Download Intel® 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
Re: [Matplotlib-users] Cannot change the fontsize in table.
It seems that you must turn off autoFontsize first. the_table.auto_set_font_size(False) then change th font size. the_table.set_fontsize(10) -JJ On Thu, Feb 25, 2010 at 12:48 PM, afancy wrote: > Hi, > > I want to generate a graph with line, and table at the bottom. However, I > found that the fontsize is very small and it is unchangeable. Could anybody > help me? thanks > > Regards > afancy > > > fig=figure() > > ax=fig.add_subplot(111) > > data=( > (0.529, 0.612, 0.855, 0.178, 1.432, 6.43, 41.311, 1.62, > 71.012, 1.59, 0.271, 0.066, 4.721), > (0.014, 0.512, 0.015, 0.161, 1.177, 6.793, 0.089, 1.495, > 25.65, 0.014, 0.045, 0.052, 5.423), > (0.493, 834.351, 0.156, 743.193,0.428, 84.101, 1058.062,8.652, > 1023, 0.168, 7.101, 8.135, 152.646), > (118.90,2035.35, 89.35, 15.402, 10.856,110.049,3024.42, > 8054.74,5214.36, 5.539, 11.539, 515.632,150.411) > ) > > rowLabels=['row1','row2', 'row3', 'row4'] > > colLabels=['Q%d'%(x+1) for x in range(13)] > > the_table = table(cellText=txtdata, rowLabels=rowLabels, > colLabels=colLabels, loc='bottom') > > the_table.set_fontsize(20.0) > > > > -- > Download Intel® 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 > > -- Download Intel® 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
Re: [Matplotlib-users] Cursor?
Did you try to turn off "useblit" option? As mentioned in the comment, that option is only supported in the agg backend. Regards, -JJ On Thu, Feb 25, 2010 at 10:45 PM, David Arnold wrote: > All, > > I tried this code from: > http://matplotlib.sourceforge.net/examples/widgets/cursor.py > > from matplotlib.widgets import Cursor > import pylab > > > fig = pylab.figure(figsize=(8,6)) > ax = fig.add_axes([0.075, 0.25, 0.9, 0.725], axisbg='#CC') > #ax = fig.add_subplot(111, axisbg='#CC') > canvas = ax.figure.canvas > > x,y = 4*(pylab.rand(2,100)-.5) > ax.plot(x,y,'o') > ax.set_xlim(-2,2) > ax.set_ylim(-2,2) > > # set useblit = True on gtkagg for enhanced performance > cursor = Cursor(ax, useblit=True, color='red', linewidth=2 ) > > pylab.show() > > I got this error on my Macbook Pro: > > The debugged program raised the exception unhandled AttributeError > "'FigureCanvasMac' object has no attribute 'copy_from_bbox'" > > Any suggestions? > > David > -- > Download Intel® 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 > -- Download Intel® 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
Re: [Matplotlib-users] Optimal positioning of text
On Sat, Feb 27, 2010 at 12:29 PM, Andrea Gavana wrote: > This code is not doing anything useful as I always get a badness of 0, > although I can see that the new text overlaps quite a lot of other > artists. > > Does anyone have some suggestion on how to improve the code? > A snippet of code seldom helps. Is your x,y input in display coordinates? Ideally, this must be checked in the drawing time (as in the legend). With your current approach, there could be lots of possible reason that this does not work. Regards, -JJ -- Download Intel® 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
Re: [Matplotlib-users] Optimal positioning of text
On 28 February 2010 01:18, Jae-Joon Lee wrote: > On Sat, Feb 27, 2010 at 12:29 PM, Andrea Gavana > wrote: >> This code is not doing anything useful as I always get a badness of 0, >> although I can see that the new text overlaps quite a lot of other >> artists. >> >> Does anyone have some suggestion on how to improve the code? >> > > A snippet of code seldom helps. > Is your x,y input in display coordinates? No, data values. > Ideally, this must be checked in the drawing time (as in the legend). This is what I am trying to do, but I messed up screen/data/canvas coordinates and I can't get my head around it :-( Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ http://thedoomedcity.blogspot.com/ -- Download Intel® 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
Re: [Matplotlib-users] Optimal positioning of text
If I read your correctly, for l, b in zip(x, y): # And here I work with data coordinates (!) dashBox = Bbox.from_bounds(l, b, width+5, height+5) badness = 0 for line in lines: if line.intersects_bbox(dashBox): badness += 1 x, y (therefore l, b) in data coordinate. width, height?? this seems to be some wx specific coordinate, i have no idea. lines (therefore line) in display coordinate. converting x,y to display coordinate should straight forward. But I'm not sure what kind of coordinate width and height has. Is it a method of some class derived from matplotlib's Text?? If then, the extent of the text can be measured using the get_window_extent method. This requires a renderer instance, which should be known if the method is called during the drawing time. Again, post a complete but simple(!) code. -JJ On Sat, Feb 27, 2010 at 8:59 PM, Andrea Gavana wrote: > On 28 February 2010 01:18, Jae-Joon Lee wrote: >> On Sat, Feb 27, 2010 at 12:29 PM, Andrea Gavana >> wrote: >>> This code is not doing anything useful as I always get a badness of 0, >>> although I can see that the new text overlaps quite a lot of other >>> artists. >>> >>> Does anyone have some suggestion on how to improve the code? >>> >> >> A snippet of code seldom helps. >> Is your x,y input in display coordinates? > > No, data values. > >> Ideally, this must be checked in the drawing time (as in the legend). > > This is what I am trying to do, but I messed up screen/data/canvas > coordinates and I can't get my head around it :-( > > Andrea. > > "Imagination Is The Only Weapon In The War Against Reality." > http://xoomer.alice.it/infinity77/ > http://thedoomedcity.blogspot.com/ > -- Download Intel® 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
Re: [Matplotlib-users] imshow size limitations?
On Sat, Feb 27, 2010 at 2:23 PM, David Goldsmith wrote: > Question 2) is there some way I can add pieces of the array incrementally to > the image into their proper place, i.e., modify the following code: > > ax.imshow(image[0:ny/2+1, 0:nx/2+1]) # upper left corner of image > ax.hold(True) > ax.imshow(argW[ny/2+1:-1, 0:nx/2+1]) # lower left corner of image > ax.imshow(argW[0:ny/2+1, nx/2+1:-1]) # upper right corner of image > ax.imshow(argW[ny/2+1:-1, nx/2+1:-1]) # lower right corner of image Try the extents keyword argument. It let's you specify the corners of the image in data coordinates. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Download Intel® 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
Re: [Matplotlib-users] mplot3d stays?
Interesting, but I think subdividing triangles like this is unnecessary. For most cases, when one triangle completely covers the other, all that is required it to Z order the triangles. This is what mplot3d does already. The only case we have yet to handle is when one triangle "pierces" the other. As seen in the attached image. Triangle B is mostly behind triangle A, except for a small piece labeled C. All we would have to do is determine the line of intersection, then create a new triangle C. Then we just draw B first, then A, then C. I think the hardest part is probably doing this for general polygons and handling the edges properly. But that should not be super hard. -Ben From: Friedrich Romstedt [friedrichromst...@gmail.com] Sent: Saturday, February 27, 2010 11:28 AM To: matplotlib-users Subject: Re: [Matplotlib-users] mplot3d stays? http://www.friedrichromstedt.org/python/pyclip/a01.Zerteilung.pdf (It's unfortunately in german, but the graphics are self-explaining) A school mate working together with me on the project has worked that out. H = number of corners of the front triangle lying inside of the back triangle V = number of corners of the back triangle lying inside of the front triangle S = number of the collinear edges of the two triangles Z = number of intersection points of the two tringles' edges, minus the number of those occuring because of collinear edges. Red: front triangle Black: back triangle Green: subdivision lines in the back triangle. I will check my implementation in C++ today. I will maybe need some advice in making a Python module out of it. Friedrich -- Download Intel® 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 <>-- Download Intel® 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
[Matplotlib-users] display image as (r, g, b) from a (3xMxN) nympy.array
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 [119]: dd[0] Out[119]: array([[[ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], ..., [ 0.22834646, 0.39370079, 0.38976378, ..., 0.2519685 , 0.25590551, 0.38582677], [ 0.30708661, 0.25984252, 0.30314961, ..., 0.2480315 , 0.25984252, 0.37401575], [ 0.58661417, 0.62598425, 0.5984252 , ..., 0.2480315 , 0.2519685 , 0.32283465]], [[ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], ..., [ 0.17322835, 0.37401575, 0.4015748 , ..., 0.27952756, 0.27559055, 0.42519685], [ 0.30314961, 0.24409449, 0.30314961, ..., 0.26771654, 0.27165354, 0.38976378], [ 0.57086614, 0.61811024, 0.5984252 , ..., 0.28346457, 0.26771654, 0.34251969]], [[ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], [ 1., 1., 1., ..., 1., 1., 1.], ..., [ 0.19685039, 0.34251969, 0.37795276, ..., 0.2519685 , 0.25984252, 0.34251969], [ 0.27165354, 0.21653543, 0.27559055, ..., 0.2519685 , 0.26377953, 0.30708661], [ 0.57480315, 0.63385827, 0.58661417, ..., 0.26377953, 0.25590551, 0.29527559]]]) 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 "", line 1, in 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 thanks for any help!!! Massimo.-- Download Intel® 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
Re: [Matplotlib-users] display image as (r, g, b) from a (3xMxN) nympy.array
On Sat, Feb 27, 2010 at 11:04 PM, Massimo Di Stefano 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 "", line 1, in > 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® 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