Re: [Matplotlib-users] 3D Data to 2d Plots
Sorry I was out of touch for a while I have been busy with other things, You would have to do some sort of a bin solution with the method I suggested. So m/z values would not have to be exact but you would group ranges of them together. To be honest based on the plots you showed in your initial question I am surprised you don’t already have the data in a 2d array already. An example of the data in the format you intend to start with would have really helped explain the situation. Matplotlib has a plot module that bins things automatically for you based on the data http://matplotlib.sourceforge.net/examples/api/histogram_demo.html or you can use numpy.historgram function directly. If you are doing something like that already to compute your m/z values, just make sure use the same sequence for your bins (see examples at http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html) and presto you have the makings of a perfectly aligned 2d array that can be plotted with pcolor or with 3d surface Again I hope this helps From: trueflyingsh...@googlemail.com [mailto:trueflyingsh...@googlemail.com] On Behalf Of Philipp A. Sent: January-28-11 10:55 AM To: Mike Alger Cc: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] 3D Data to 2d Plots 2011/1/28 Mike Alger mal...@ryerson.ca Philip, A few questions before I give one possible solution, Does this plot need to be updated in real time ? or is this plot to be done in post processing? if you can do the plots with post processing you should be able to use pcolor function to do your tasks http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo.html i won’t go into details but just assign: X as 1d vector with your m/z values Y as 1d vector your time values And Z as a 2d array that will map counts/sec to both a “m/z” and “time” index You will have to find the location for your other marks and then plot them on top of pcolor graph but that shouldn’t be too hard just express your values (i am assuming 3dB cutoff points and peak power of some sort) in terms of X Y. I am almost certain there is probably a nice DSP way to solve for those X Y values once the data is in a 2d array but i am no expert on that mater. Good luck and hopefully this helps, Mike hi mike, thanks for the answer. it looks interesting, but will it work if the m/z values are all different from each other? i mean: the m/z-ranges are overlapping, but there are no duplicate values. this way, every column of the array would only contain one value if i understood you correctly. thanks, philipp -- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 3D Data to 2d Plots
Philip, A few questions before I give one possible solution, Does this plot need to be updated in real time ? or is this plot to be done in post processing? if you can do the plots with post processing you should be able to use pcolor function to do your tasks http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo.html i won’t go into details but just assign: X as 1d vector with your m/z values Y as 1d vector your time values And Z as a 2d array that will map counts/sec to both a “m/z” and “time” index You will have to find the location for your other marks and then plot them on top of pcolor graph but that shouldn’t be too hard just express your values (i am assuming 3dB cutoff points and peak power of some sort) in terms of X Y. I am almost certain there is probably a nice DSP way to solve for those X Y values once the data is in a 2d array but i am no expert on that mater. Good luck and hopefully this helps, Mike From: Philipp A. [mailto:flying-sh...@web.de] Sent: January-27-11 5:15 PM To: matplotlib-users@lists.sourceforge.net Subject: [Matplotlib-users] 3D Data to 2d Plots Hi list, I want to visualize Plots over time. This describes the data: 3dplot.png http://red-sheep.de/images/3dplot.png a) and b) are single scans, the cutting at the red bars is no problem. c) illustrates how they are done over time. d) is what I want. I think this plot http://matplotlib.sourceforge.net/examples/axes_grid/demo_axes_grid2.html could be a starting point, but I don’t really understand what’s done there. e) would be easier to do, like this plot http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html , but information is lost this way (hidden behind higher values) it would be best to do the following: 1. plot one horizontal line vertically above each other (gapless), one for each scan (so the vertical axis is the time axis) 2. each line is displayed as a series of gradients directly next to to each other (gapless) 3. the starting and ending point of each gradient are determined by the horizontal position of two adjacent data points in the current scan 4. the colors of each gradient are determined by the vertical position of the two adjacent data points in the current scan, relative to the total maximum has anyone an idea how to do this? i am really a matplotlib noob. Philipp -- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] color in plot3d
Pablo, I found the example on the svn http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/examples/mplot3d/surface3d_demo3.py?view=log http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/examples/mplot3d/surface3d_demo3.py?view=log it will demonstrate the face colour thing but personally I found getting the rgb tuple data into an array a bit too complicated for my needs. Regarding that little SNAFU about the matrix size, I was half asleep and in a rush when I wrote the reply to your email, so I knew if I made a mistake it was in the interpretation there :D A slice, reshape function may be more efficient/ easier to read but I took the loop structure right from the plot surface command to make sure it was done exactly the same way as the 3d surface. It may be interesting to see which is more efficient computationally and see if there is an improvement to be made in the plot surface command From: Pablo Angulo [mailto:pablo.ang...@uam.es] Sent: June-16-10 9:07 AM To: Mike Alger Cc: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] color in plot3d El 15/06/10 01:22, Mike Alger escribió: The way that color keyword is set up, it is dedsigned to take a color word or rgba tuple , (Reinier will know this better than me), however if you want to just assign colors based on a colour map you can take you color array and reshape the same way the plot surface command does then use surf.set_array() If I understand you correctly, you mean there is a way to use directly a map from two or three spatial coordinates into the three or four components of the color space? That's interesting. It might be limiting that this map has to factor as the composition of an scalar map and a color map, even for 2d plots. here is a snippet of the code I use to do this I am pretty sure it won’t run the way it is right now but the idea is buried in there Thanks, I got the idea! note that regmap xyz and costmapz are all the same size and are nxm matrices costmapout is a 2x(m.n) if i can do the math correctly One comment: from your code it seems that costmapout is a 1D array of lenght roughly equal (m*n)/scale**2 with the data coming from costmapz. Why don't you use a slice followed by a reshape command? No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.829 / Virus Database: 271.1.1/2942 - Release Date: 06/16/10 14:35:00 -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] color in plot3d
First what version of mpl are you using? if it is recent this colour word already exists, I asked about this a couple months ago and i should point you first to the example in the svn it does a checkerboard, but i cannot remember the exact name. Although i know it plots a checkerboard effect on one of the example plots. The way that color keyword is set up, it is dedsigned to take a color word or rgba tuple , (Reinier will know this better than me), however if you want to just assign colors based on a colour map you can take you color array and reshape the same way the plot surface command does then use surf.set_array() here is a snippet of the code I use to do this I am pretty sure it won’t run the way it is right now but the idea is buried in there note that regmap xyz and costmapz are all the same size and are nxm matrices costmapout is a 2x(m.n) if i can do the math correctly from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import numpy as np #-- ax = Axes3D(fig) scale= 3 surf = ax.plot_surface(regMAPx ,regMAPy,-regMAPz , rstride=scale,cstride=scale, cmap=cm.jet, linewidth=.250 ) # to reshape the cost map to match grid used in plot surf rows, cols = costMAPz.shape costmapout = [] for rs in np.arange(0, rows-1, scale): for cs in np.arange(0, cols-1, scale): costmapout.append(costMAPz[rs][cs]) costmapout=np.array(costmapout) surf.set_array(costmapout) ## do your show plot stuff here!! Mike Alger From: Pablo Angulo [mailto:pablo.ang...@uam.es] Sent: June-11-10 7:04 AM To: matplotlib-users@lists.sourceforge.net Subject: [Matplotlib-users] color in plot3d Hello! I wonder if there is a way to make 3d plots specifying arbitrary colors, instead of having the color be a function of the height. I was able to achieve this making minimal changes to the plot_surface method of Axes3D, adding as an optional keyword argument a function cfun which specifies the color (it specifies a real number that is mapped into a color by the color map cmap). But is there a standard way? Regard Pablo Angulo from matplotlib.colors import Normalize, colorConverter def plot_surface(self, X, Y, Z, *args, **kwargs): ''' Create a surface plot. By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. == ArgumentDescription == *X*, *Y*, Data values as numpy.arrays *Z* *rstride* Array row stride (step size) *cstride* Array column stride (step size) *color* Color of the surface patches *cmap* A colormap for the surface patches. *cfun* The function giving the color == ''' had_data = self.has_data() rows, cols = Z.shape tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z) rstride = kwargs.pop('rstride', 10) cstride = kwargs.pop('cstride', 10) color = kwargs.pop('color', 'b') color = np.array(colorConverter.to_rgba(color)) cmap = kwargs.get('cmap', None) cfun = kwargs.pop('cfun', None) polys = [] normals = [] avgz = [] if not cfun: cfun = lambda p:p[2] for rs in np.arange(0, rows-1, rstride): for cs in np.arange(0, cols-1, cstride): ps = [] corners = [] for a, ta in [(X, tX), (Y, tY), (Z, tZ)]: ztop = a[rs][cs:min(cols, cs+cstride+1)] zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)] zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):] zbase = zbase[::-1] zright = ta[cs][rs:min(rows, rs+rstride+1):] zright = zright[::-1] corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]]) z = np.concatenate((ztop, zleft, zbase, zright)) ps.append(z) # The construction leaves the array with duplicate points, which # are removed here. ps = zip(*ps) lastp = np.array([]) ps2 = [] avgzsum = 0.0 for p in ps: if p != lastp: ps2.append(p) lastp = p avgzsum += cfun(p) polys.append(ps2) avgz.append(avgzsum / len(ps2)) v1 = np.array(ps2[0]) - np.array(ps2[1]) v2 = np.array(ps2[2]) - np.array(ps2[0]) normals.append(np.cross(v1, v2)) polyc = art3d.Poly3DCollection(polys, *args, **kwargs) if cmap is not None: polyc.set_array(np.array(avgz)) polyc.set_linewidth(0
Re: [Matplotlib-users] axis equal
Unfortunately i have not found such a function as of yet and the function that sound close to it (aspect) only controls the windows aspect ratio Fortunately there is a quick and dirty work around I have found the following to be useful Assuming you have X Y Z matrices made using meshgrid or some other means from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = Axes3D(fig) u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 50 * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') Xstart=(x.min()) Xend =(x.max()) Ystart=(y.min()) Zstart=(z.min()) Scalex=(Xend-Xstart) ax.set_xlim3d(Xstart,Xstart+Scale) ax.set_ylim3d(Ystart,Ystart+Scale) ax.set_zlim3d(Zstart,Zstart+Scale) plt.show() again I have made the assumption that the plot is squarish in the x and y direction, a more robust version would test to see which is the biggest scalex,scaley,scalez center the other axis value but again i just coded this in 5 min as an example -Original Message- From: David Arnold [mailto:dwarnol...@suddenlink.net] Sent: December-07-09 12:30 PM To: matplotlib-users@lists.sourceforge.net Subject: [Matplotlib-users] axis equal All, Is there an axis equal command for mplot3d? D. -- Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Color in 3d plots
Sorry i was getting a bit frustrated by checking every day and seeing other problems getting solved relativly fast, again i understand its a big project, and i do appreciate your time, i hope i didn`t come off as a complete jerk. I figured since my suggested change would affect how others would interact with the existing function i should defer some interface design decisions to someone more familiar with the API and the interface philosophy before i would start suggesting my hacks to the code to get it to do what i want. again, i would love to build this functionality into the existing code, and it think it could be done via a good choice of kwargs parameters. Again i know how i can do this for my particular solution but how this should be done to minimize the effect on other users of the code i am not sure. thanks again for the response, i was going a bit crazy as i saw MPL as the perfect solution as it does just about everything i need except that one tiny variation in the surface command and i didn't want to rule it out its use in a user interface project i have work on in the coming months because of it. Mike - Original Message - From: John Hunter jdh2...@gmail.com Date: Monday, November 30, 2009 11:26 pm Subject: Re: [Matplotlib-users] Color in 3d plots To: Mike Alger mal...@ryerson.ca Cc: matplotlib-users@lists.sourceforge.net, Reinier Heeres rein...@heeres.eu On Mon, Nov 30, 2009 at 8:06 PM, Mike Alger mal...@ryerson.ca wrote: After a weekend of no replies I managed to figure a way out myself Hey Mike, sorry for the radio silence. mpl is a big project and no one developer is equipped to answer questions about everything. We currently have only one active developer (Reinier) working on the 3D stuff. I've CCd him, and hopefully he can take a look at your patch. 3.)If I do make a modification should it be as a separate function with the additional variable or should I try to stuff the new capability into the old function 4.)is there a clean easy to follow tutorial for submitting changes via svn or can I rely on someone else to do the final commit? In general, if the new functionality is close to the old, we'd like to see it incorporated into the existing API, perhaps with a new keyword argument. We have some documentation on how to contribute to mpl at http://matplotlib.sourceforge.net/devel/coding_guide.html; see also the FAQ http://matplotlib.sourceforge.net/faq/howto_faq.html#contributing-howto As this was “left to the reader as an exercise” I will leave the integration or improvement of this solution as an exercise to the next reader What I have done is basically cloned the plot surface function and replaced the avgz variable with a reference to the “colors” parameter i have added to the function call. This code doesn’t center things perfectly with respect to the grid (for some reason a 40x40 grid turns into 39x39 grid in the function) again this is something else that could be improved, however I am happy with it and a one pixel shift won’t be missed in my plots. I also have no real clue as to what the following comments was about # The construction leaves the array with duplicate points, which # are removed here. but it is probably related to my non centered plots. What follows is the modified function : def plot_surface2(self, X, Y, Z, colors, *args, **kwargs): What will be most helpful is an svn diff, as explained in the coding guide and FAQ linked above, with an example (included in the diff) that shows the before and after behavior. That way even an naive developer can appreciate the before and after changes and commit the code if the original developer responsible for that part of the code base is not available. The ideal situation is apply this patch generated from an svn diff and run example so_and_so.py to see the plot with and without the patch. As explained in the FAQ, if you don't get proper attention here on the mailing list, please post a bug or patch on the sourceforge tracker so we don't lose it -- sometimes our inattention is not due to lack of interest but to lack of time, and a report filed on the tracker helps us not lose the thread. Thanks for the help! JDH -- Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Color in 3d plots
After a weekend of no replies I managed to figure a way out myself As this was left to the reader as an exercise I will leave the integration or improvement of this solution as an exercise to the next reader What I have done is basically cloned the plot surface function and replaced the avgz variable with a reference to the colors parameter i have added to the function call. This code doesn't center things perfectly with respect to the grid (for some reason a 40x40 grid turns into 39x39 grid in the function) again this is something else that could be improved, however I am happy with it and a one pixel shift won't be missed in my plots. I also have no real clue as to what the following comments was about # The construction leaves the array with duplicate points, which # are removed here. but it is probably related to my non centered plots. What follows is the modified function : def plot_surface2(self, X, Y, Z, colors, *args, **kwargs): ''' Create a surface plot. By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. == ArgumentDescription == *X*, *Y*, Data values as numpy.arrays *Z* *colors* an array the same size as z that contains a separate color data *rstride* Array row stride (step size) *cstride* Array column stride (step size) *color* Color of the surface patches *cmap* A colormap for the surface patches. == ''' had_data = self.has_data() rows, cols = Z.shape tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z) rstride = kwargs.pop('rstride', 10) cstride = kwargs.pop('cstride', 10) color = kwargs.pop('color', 'b') color = np.array(colorConverter.to_rgba(color)) cmap = kwargs.get('cmap', None) polys = [] normals = [] avgz = [] for rs in np.arange(0, rows-1, rstride): for cs in np.arange(0, cols-1, cstride): ps = [] corners = [] for a, ta in [(X, tX), (Y, tY), (Z, tZ)]: ztop = a[rs][cs:min(cols, cs+cstride+1)] zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)] zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):] zbase = zbase[::-1] zright = ta[cs][rs:min(rows, rs+rstride+1):] zright = zright[::-1] corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]]) z = np.concatenate((ztop, zleft, zbase, zright)) ps.append(z) # The construction leaves the array with duplicate points, which # are removed here. ps = zip(*ps) lastp = np.array([]) ps2 = [] avgzsum = 0.0 for p in ps: if p != lastp: ps2.append(p) lastp = p avgzsum += p[2] polys.append(ps2) ## Begin of changes ## #avgz.append(avgzsum / len(ps2)) avgz.append(colors[rs][cs]) ## end of changes ## v1 = np.array(ps2[0]) - np.array(ps2[1]) v2 = np.array(ps2[2]) - np.array(ps2[0]) normals.append(np.cross(v1, v2)) polyc = art3d.Poly3DCollection(polys, *args, **kwargs) if cmap is not None: # polyc.set_array(np.array(colors)) polyc.set_array(np.array(avgz)) polyc.set_linewidth(0) else: colors = self._shade_colors(color, normals) polyc.set_facecolors(colors) self.add_collection(polyc) self.auto_scale_xyz(X, Y, Z, had_data) return polyc From: Mike Alger [mailto:mal...@ryerson.ca] Sent: November-25-09 8:42 PM To: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] Color in 3d plots I have been looking at this for the past day and in am pretty sure I could replace the instance of polyc by the cmap if statements my colour array and I should be able to get close to what I want. However I am new to both python mpl, and I am not entirely sure in how I would go about testing my hypothesis. Furthermore I am also
[Matplotlib-users] Color in 3d plots
This may be a dumb question, however i have been scratching my head trying to figure out how to plot a 3 dimensional plot with with a colour map different from the elevation(Z) parameter. An example of this done in Matlab would be [X,Y,Z] = peaks(30); C=Z'% could be anything other than Z as long as it has the same dimensions surf(X,Y,Z,C) axis([-3 3 -3 3 -10 5]) Is this possible with matplotlib '0.99.1' If so how do i go about doing this is there some sample code? Mike Alger, M.A.Sc mal...@ryerson.ca -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Color in 3d plots
I have been looking at this for the past day and in am pretty sure I could replace the instance of polyc by the cmap if statements my colour array and I should be able to get close to what I want. However I am new to both python mpl, and I am not entirely sure in how I would go about testing my hypothesis. Furthermore I am also relatively new to submitting fixes to open-source projects so I have lots of questions about how I would go about suggesting a modification. 1.)can I just modify the file in the C:\python26\Lib\site-packages\mpl-toolkits\mplot3d\axes3d.py file to do my tests? a. Also, where are these files usually kept in a linux environment ? b. What do I do with the. pyc files with the same name? are they re-complied automatically when I call the function externally? 2.)Is this capability already built in with the colour argument ? if so how do I properly call it? 3.)If I do make a modification should it be as a separate function with the additional variable or should I try to stuff the new capability into the old function 4.)is there a clean easy to follow tutorial for submitting changes via svn or can I rely on someone else to do the final commit? I have attached the function in question for reference to save others from digging down into their python directories Again thanks for taking your time to help me figure this out Mike Alger Code def plot_surface(self, X, Y, Z, *args, **kwargs): ''' Create a surface plot. By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. == ArgumentDescription == *X*, *Y*, Data values as numpy.arrays *Z* *rstride* Array row stride (step size) *cstride* Array column stride (step size) *color* Color of the surface patches *cmap* A colormap for the surface patches. == ''' had_data = self.has_data() rows, cols = Z.shape tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z) rstride = kwargs.pop('rstride', 10) cstride = kwargs.pop('cstride', 10) color = kwargs.pop('color', 'b') color = np.array(colorConverter.to_rgba(color)) cmap = kwargs.get('cmap', None) polys = [] normals = [] avgz = [] for rs in np.arange(0, rows-1, rstride): for cs in np.arange(0, cols-1, cstride): ps = [] corners = [] for a, ta in [(X, tX), (Y, tY), (Z, tZ)]: ztop = a[rs][cs:min(cols, cs+cstride+1)] zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)] zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):] zbase = zbase[::-1] zright = ta[cs][rs:min(rows, rs+rstride+1):] zright = zright[::-1] corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]]) z = np.concatenate((ztop, zleft, zbase, zright)) ps.append(z) # The construction leaves the array with duplicate points, which # are removed here. ps = zip(*ps) lastp = np.array([]) ps2 = [] avgzsum = 0.0 for p in ps: if p != lastp: ps2.append(p) lastp = p avgzsum += p[2] polys.append(ps2) avgz.append(avgzsum / len(ps2)) v1 = np.array(ps2[0]) - np.array(ps2[1]) v2 = np.array(ps2[2]) - np.array(ps2[0]) normals.append(np.cross(v1, v2)) polyc = art3d.Poly3DCollection(polys, *args, **kwargs) ## this is where a modification could be made to allow for a separate colour matrix if cmap is not None: polyc.set_array(np.array(avgz)) polyc.set_linewidth(0) else: colors = self._shade_colors(color, normals) polyc.set_facecolors(colors) self.add_collection(polyc) self.auto_scale_xyz(X, Y, Z, had_data) return polyc /Code From: Mike Alger [mailto:mike.al...@ngcaerospace.com] Sent: November-23-09 3:42 PM To: matplotlib-users@lists.sourceforge.net Subject: [Matplotlib-users] Color in 3d plots This may be a dumb question, however I have been scratching my head trying to figure out how to plot a 3 dimensional plot with with a colour map different from the elevation(Z) parameter