SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S


1
(24)
2
(35)
3
(21)
4
(15)
5
(1)
6
(2)
7
(30)
8
(16)
9
(11)
10
(10)
11
(10)
12
(4)
13
(2)
14
(14)
15
(21)
16
(7)
17
(5)
18
(2)
19
(5)
20
21
(4)
22
(8)
23
(4)
24
(6)
25
(2)
26
(2)
27
(5)
28
(9)
29
(16)
30
(14)
31
(5)


Showing 9 results of 9

From: Reinier H. <re...@he...> - 2009年12月10日 23:37:13
Attachments: contours.jpg
Hi,
I just committed a patch to do this in svn, also allowing for contour
lines along other directions.
See the attached image for an example.
Cheers,
Reinier
On Thu, Dec 3, 2009 at 10:01 AM, Matthias Michler
<Mat...@gm...> wrote:
> Thanks a lot!
>
> Regards,
> Matthias
>
> On Wednesday 02 December 2009 17:10:54 Reinier Heeres wrote:
>> Hi Matthias,
>>
>> I have a similar patch lying around somewhere, and I will try to apply
>> it soon. I've been terribly busy lately, but I expect some nice
>> mplot3d enhancements in the very near future.
>>
>> Regards,
>> Reinier
>>
>> On Wed, Dec 2, 2009 at 4:22 PM, Matthias Michler
>>
>> <Mat...@gm...> wrote:
>> > Hi Andrew,
>> >
>> > do you have any idea if the patch (or a part of it) may get a part of
>> > matplotlib-svn some day?
>> >
>> > Kind regards,
>> > Matthias
>> >
>> > On Friday 09 October 2009 23:25:28 Andrew Straw wrote:
>> >> Matthias Michler wrote:
>> >> > Hello list,
>> >> >
>> >> > I'm not an expert in axes3d, but in case the feature which Nicolas
>> >> > requested is not possible in an easy manner up to now, I propose an
>> >> > additional kwarg for axes3d.Axes3D.contour. Something like *offset*.
>> >> > If offset is None the z-values of the contour lines corresponds to
>> >> > given Z and otherwise offset is used for the z-values of the contour
>> >> > lines. I attached a changed axes3d.py and a patch against current svn.
>> >> > The result is illustrated in the contour3d_demo.png.
>> >> >
>> >> > Could any of the experts have a look at it and tell me if this could
>> >> > be useful, please?
>> >> >
>> >> > Thanks in advance for any comments.
>> >> >
>> >> > Kind regards
>> >> > Matthias
>> >> >
>> >> > On Wednesday 30 September 2009 19:22:42 Nicolas Bigaouette wrote:
>> >> >> Hi,
>> >> >> I have a nice plot_surface() using mplot3d (see attachement).
>> >> >>
>> >> >> I'd like to project the surface on the axis xoy, xoz and yoz with a
>> >> >> contour, similar to this figure:
>> >> >> http://homepages.ulb.ac.be/~dgonze/INFO/matlab/fig19.jpg
>> >> >>
>> >> >> Is it possible using matplotlib and mplot3d?
>> >> >>
>> >> >> Thanx!
>> >>
>> >> Hi Matthias,
>> >>
>> >> I committed your patch to a github branch of MPL, but I'll let Reinier
>> >> actually commit something based on this to MPL.
>> >> http://github.com/astraw/matplotlib/tree/dev/michler-3d-contourf-offsets
>> >>
>> >> -Andrew
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
-- 
Reinier Heeres
Tel: +31 6 10852639
From: Marius J. K. <mj...@ny...> - 2009年12月10日 19:26:50
I use to save my plots as tiff. The color model of these plots is RGB. Can I change it to CMYK?
From: Eric F. <ef...@ha...> - 2009年12月10日 17:45:55
mar...@if... wrote:
> 
> Hello,
> 
> let's say I have given an image of distance values, which I display with 
> the jet colormap. Now if there are invalid pixels within the image they 
> have the value -1 or -2. Is there a way to display just the "valid" 
> image with the jet colorbar and the -1 pixels as white pixels and the -2 
> pixels as black pixels?
See 
http://matplotlib.sourceforge.net/examples/pylab_examples/image_masked.html.
You might need to use a masked array and mask the -2 values.
Eric
> 
> Till now I scale the image with vmin, vmax:
> 
> >>> vmin = img[(img != -1) & (img != -2)].min()
> >>> vmax = img[(img != -1) & (img != -2)].max()
> >>> imshow(img, vmin=vmin, vmax=vmax, interpolation = 'nearest')
> 
> But how can I now paint the black and white pixels?
> 
> Regards,
> 
> Markus
> 
> 
> ------------------------------------------------------------------------
> 
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Pierre de B. <pd...@ul...> - 2009年12月10日 14:55:37
Hello,
According to http://matplotlib.sourceforge.net/api/ 
pyplot_api.html#matplotlib.pyplot.scatter , the keyword argument that 
takes an array to specify the colors of the individual markers is c. 
color is interpreted as a color to give to all markers at once.
The following works on my computer (matplotlib 0.99.0) :
import numpy as N
from matplotlib import pyplot as P
x = N.random.randn(100)
y = N.random.randn(100)
z = N.random.randn(100)**2
fig = P.figure()
ax = fig.add_subplot(1,1,1)
cmap = P.matplotlib.cm.jet
norm = P.matplotlib.colors.Normalize(vmin=0, vmax=1)
sc = ax.scatter(x,y,
 c=z,
 cmap=cmap,
 norm=norm,
 )
Le 10 déc. 09 à 14:44, Yannick Copin a écrit :
> Hi,
>
> according to the documentation, scatter should accept a 1D float 
> array for
> color kwarg. Therefore, I thought the following code would work 
> (and I think
> it worked at some point in the past; I'm currently using matplotlib 
> 0.99.0):
>
> import numpy as N
> from matplotlib import pyplot as P
>
> x = N.random.randn(100)
> y = N.random.randn(100)
> z = N.random.randn(100)**2
>
> fig = P.figure()
> ax = fig.add_subplot(1,1,1)
>
> cmap = P.matplotlib.cm.jet
> norm = P.matplotlib.colors.Normalize(vmin=0, vmax=1)
>
> sc = ax.scatter(x,y,
> color=z,
> cmap=cmap,
> norm=norm,
> )
>
> But this crashes with the following error:
>
> [...]
From: Michael C. <mc...@ca...> - 2009年12月10日 09:18:10
Thanks, the svn version is working nicely.
Cheers
Mike
On 12/09/2009 01:21 PM, Michael Droettboom wrote:
> I can confirm this bug on matplotlib-0.99.0, and 0.99.1.2, but not on
> SVN head. I think this is related to a recently fixed bug involving the
> renderer outputting single-point lines (which obviously doesn't make
> sense, and Postscript has problems with).
>
> You can either install from SVN (I recommend using the 0.99.x branch
> [1], rather than the trunk), or set the rcParam 'path.simplify' to
> False. Unfortunately, the latter will result in some very large file sizes.
>
> [1] https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_99_maint
>
> Cheers,
> Mike
>
> Michael Cohen wrote:
>> Hi there,
>> Does anyone know what might be the problem with this EPS write?
>> Please see my email of Dec 6th for the attachments.
>>
>> Regards,
>> Michael
>>
>> Michael Cohen wrote:
>>> Hi,
>>>
>>> Sorry for taking a few days to reply.
>>> Basic system information
>>>
>>> $ uname -a
>>> Linux shc-b 2.6.18-128.1.10.el5 #1 SMP Wed Apr 29 13:53:08 EDT 2009
>>> x86_64 x86_64 x86_64 GNU/Linux
>>> $ head -n1 /etc/issue
>>> Red Hat Enterprise Linux Server release 5.3 (Tikanga)
>>> $
>>>
>>> matplotlibrc attached.
>>>
>>> plot_test.py attached also.
>>>
>>> $ python
>>> Python 2.6.2 (r262:71600, Sep 16 2009, 13:37:23)
>>> [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>> >>> import matplotlib
>>> >>> print matplotlib.__version__
>>> 0.99.0
>>> >>>
>>>
>>> finally, failed output eps also attached.
>>>
>>> The plot generates a set of horizontal and vertical lines to make a
>>> grid, and then applies the Mollweide projection to give latitude and
>>> longitude lines.
>>> For some reason, not running the projection (i.e. lines 43-51 in the
>>> python script) gives a file that outputs as a nice eps. If you do
>>> keep the Mollweide projection in, you still generate a lovely plot,
>>> but the savefig to .eps fails.
>>>
>>> Thanks,
>>> Michael
>>>
>>>
>>> John Hunter wrote:
>>>> On Wed, Dec 2, 2009 at 3:20 PM, Michael Cohen <mc...@ca...>
>>>> wrote:
>>>>> Hi,
>>>>> To add more information. I am trying this on two separate installs of
>>>>> matplotlib 0.99, both using TkAgg as the backend. One produces an
>>>>> unreadable file, the other does produce a readable EPS. However, even
>>>>> in this case, zooming in on the image shows that what is being
>>>>> saved is
>>>>> bitmapped, not a vector graphic.
>>>> Could you please post some sample code and the EPS it generates, as
>>>> well as platform information and any specific rc settings you may
>>>> have?
>>>>
>>>> Thanks,
>>>> JDH
>>
>> ------------------------------------------------------------------------------
>>
>> Return on Information:
>> Google Enterprise Search pays you back
>> Get the facts.
>> http://p.sf.net/sfu/google-dev2dev
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: <mar...@if...> - 2009年12月10日 08:21:49
Hello,
let's say I have given an image of distance values, which I display with 
the jet colormap. Now if there are invalid pixels within the image they 
have the value -1 or -2. Is there a way to display just the "valid" image 
with the jet colorbar and the -1 pixels as white pixels and the -2 pixels 
as black pixels?
Till now I scale the image with vmin, vmax:
>>> vmin = img[(img != -1) & (img != -2)].min()
>>> vmax = img[(img != -1) & (img != -2)].max()
>>> imshow(img, vmin=vmin, vmax=vmax, interpolation = 'nearest')
But how can I now paint the black and white pixels?
Regards,
Markus
From: Mike A. <ma...@ry...> - 2009年12月10日 01:17:00
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:dwa...@su...] 
Sent: December-07-09 12:30 PM
To: mat...@li...
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
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Reinier H. <re...@he...> - 2009年12月10日 00:44:42
Hi Mike,
Sorry for the slow reply, but I put support for this in the
development version in SVN. It can also do a bit of shading to make
the surface look more structured.
Note that the fact that a 40x40 grid turns into 39x39 squares is
expected behavior: the code assumes the 40 points are the *edges* of
the patches. There are only 39 patches between 40 points.
Regards,
Reinier
On Tue, Dec 1, 2009 at 3:06 AM, Mike Alger <ma...@ry...> wrote:
> 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.
>
>
>
>     ========== ================================================
>
>     Argument  Description
>
>     ========== ================================================
>
>     *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:ma...@ry...]
> Sent: November-25-09 8:42 PM
> To: mat...@li...
> 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 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.
>
>
>
>     ========== ================================================
>
>     Argument  Description
>
>     ========== ================================================
>
>     *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:mik...@ng...]
> Sent: November-23-09 3:42 PM
> To: mat...@li...
> 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.
>
>
>
> 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
>
> ma...@ry...
>
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
-- 
Reinier Heeres
Tel: +31 6 10852639
From: Mike A. <ma...@ry...> - 2009年12月10日 00:39:19
I had a hunch that was the case but wasn`t entirely sure, and to be honest
3d plot functions have always been a black box for me and i have never
really thought about what exactly gets plotted in 3d plot until now
Thanks again 
Reinier i will take a look at the SVN A.S.A.P. 
Mike
-----Original Message-----
From: Reinier Heeres [mailto:re...@he...] 
Sent: December-09-09 7:17 PM
To: Mike Alger
Cc: mat...@li...
Subject: Re: [Matplotlib-users] Color in 3d plots
Hi Mike,
Sorry for the slow reply, but I put support for this in the
development version in SVN. It can also do a bit of shading to make
the surface look more structured.
Note that the fact that a 40x40 grid turns into 39x39 squares is
expected behavior: the code assumes the 40 points are the *edges* of
the patches. There are only 39 patches between 40 points.
Regards,
Reinier
On Tue, Dec 1, 2009 at 3:06 AM, Mike Alger <ma...@ry...> wrote:
> 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.
>
>
>
>     ========== ================================================
>
>     Argument  Description
>
>     ========== ================================================
>
>     *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:ma...@ry...]
> Sent: November-25-09 8:42 PM
> To: mat...@li...
> 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 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.
>
>
>
>     ========== ================================================
>
>     Argument  Description
>
>     ========== ================================================
>
>     *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:mik...@ng...]
> Sent: November-23-09 3:42 PM
> To: mat...@li...
> 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.
>
>
>
> 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
>
> ma...@ry...
>
>
>
>
----------------------------------------------------------------------------
--
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
-- 
Reinier Heeres
Tel: +31 6 10852639
1 message has been excluded from this view by a project administrator.

Showing 9 results of 9

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /