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





Showing 12 results of 12

From: Feng Yu <rai...@gm...> - 2011年10月05日 22:40:05
Dear Lists,
I tried to draw a white block with alpha-channel gradient on top of black.
The result appears to be non-linear, and I think it is problematic.
image = ones((255, 255, 4), dtype='u1')
image[:, :, 0:3] = 255
image[:, :, 3] = arange(0, 255)[:, newaxis]
gca().set_axis_bgcolor('k')
imshow(image)
The color of the pixel with alpha = 128 is about (30, 30, 30).
We can confirm this with
cla()
image[:, :, 3] = 128
imshow(image)
On Inkscape, a white block with alpha = 128 on top of a black box gives a
final color of r,g,b=128, 128, 128.
I did a rough fit and apparently matplotlib is calculating the final pixel
brightness with (notice the original pixel is 0)
r = cr * (alpha / 255.) ** 3 , (same for g and b)
shouldn't it be r = cr * alpha / 255?
This affects matplotlib-1.0.1 and a not so recent copy of the git
master(ba4043a35d4c2).
Regards,
Yu
From: Ethan G. <eth...@gm...> - 2011年10月05日 20:23:32
Holger, for what it is worth, you can hack this fairly easily. Run the
code twice once with colors, once with shading. Take the output from
both as images, the convert both images to HSV, the recombine the HS
components from the color version with the V component of the shaded
version. I haven't done this in matplotlib, but it worked great for me
in IDL.
On Oct 5, 2011, at 1:23 PM, Holger Brandsmeier
<hol...@sa...> wrote:
> Ben,
>
> I would be very happy to have this functionality. I think this would
> also make the 3D plots in the examples that matplot provides look a
> good deal nicer.
>
> Let me know if you have any updates on this.
>
> -Holger
>
> On Mon, Oct 3, 2011 at 21:18, Benjamin Root <ben...@ou...> wrote:
>>
>>
>> On Fri, Sep 30, 2011 at 11:33 AM, Holger Brandsmeier
>> <hol...@sa...> wrote:
>>>
>>> Ben,
>>>
>>> On Fri, Sep 30, 2011 at 17:06, Benjamin Root <ben...@ou...> wrote:
>>>> What values for rstride and cstride are you using? By default,
>>>> plot_surface() will sample every 10th point of the data array (for
>>>> performance reasons). Also, color interpoltion can be turned on by
>>>> setting
>>>> shade to True.
>>>
>>> I beleive I start to understand the underlying logic. If no color map
>>> is set and shading and antialiazing is set, then indeed the surface
>>> is nicely and smoothly displayed. When I provide a color map, then I
>>> seem to be able to assign one color for the whole polygon. I also find
>>> something like that in the code.
>>>
>>> In my case I want the z-coordinate to determine the color. I want to
>>> use a colormap like jet and no transparency. If I don't use the
>>> colormap argument, then I get shading, however everything is blue with
>>> shading depending on a lightsource.I don't really need a lightsource,
>>> but I would like non-constant colors per polygon.
>>>
>>
>> Yes, you have the logic correct (and probably better explained than I could
>> have done). This actually was an issue raised a couple of months ago in a
>> bit of a different context, but the solution wasn't entirely clear at that
>> point. However, looking at the code again (remember, I didn't write it
>> originally, and it had next to no comments), I think I see a fairly simple
>> solution. If I allow for the user to specify a light source of None, then I
>> could feed the data through a different function to "shade" the surface. I
>> will look into doing that, but it won't make it into the v1.1.0 release
>> (slated for tomorrow).
>>
>> Cheers!
>> Ben Root
>>
>>
>
>
>
> --
> Holger Brandsmeier, SAM, ETH Zürich
> http://www.sam.math.ethz.ch/people/bholger
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Holger B. <hol...@sa...> - 2011年10月05日 18:21:43
Ben,
I would be very happy to have this functionality. I think this would
also make the 3D plots in the examples that matplot provides look a
good deal nicer.
Let me know if you have any updates on this.
-Holger
On Mon, Oct 3, 2011 at 21:18, Benjamin Root <ben...@ou...> wrote:
>
>
> On Fri, Sep 30, 2011 at 11:33 AM, Holger Brandsmeier
> <hol...@sa...> wrote:
>>
>> Ben,
>>
>> On Fri, Sep 30, 2011 at 17:06, Benjamin Root <ben...@ou...> wrote:
>> > What values for rstride and cstride are you using? By default,
>> > plot_surface() will sample every 10th point of the data array (for
>> > performance reasons). Also, color interpoltion can be turned on by
>> > setting
>> > shade to True.
>>
>> I beleive I start to understand the underlying logic. If no color map
>> is set and shading and antialiazing is set, then indeed the surface
>> is nicely and smoothly displayed. When I provide a color map, then I
>> seem to be able to assign one color for the whole polygon. I also find
>> something like that in the code.
>>
>> In my case I want the z-coordinate to determine the color. I want to
>> use a colormap like jet and no transparency. If I don't use the
>> colormap argument, then I get shading, however everything is blue with
>> shading depending on a lightsource.I don't really need a lightsource,
>> but I would like non-constant colors per polygon.
>>
>
> Yes, you have the logic correct (and probably better explained than I could
> have done). This actually was an issue raised a couple of months ago in a
> bit of a different context, but the solution wasn't entirely clear at that
> point. However, looking at the code again (remember, I didn't write it
> originally, and it had next to no comments), I think I see a fairly simple
> solution. If I allow for the user to specify a light source of None, then I
> could feed the data through a different function to "shade" the surface. I
> will look into doing that, but it won't make it into the v1.1.0 release
> (slated for tomorrow).
>
> Cheers!
> Ben Root
>
>
-- 
Holger Brandsmeier, SAM, ETH Zürich
http://www.sam.math.ethz.ch/people/bholger
From: Leidner, M. <mle...@ae...> - 2011年10月05日 13:50:20
 
Ben,
 
I am finally replying to your most helpful post about shapefile generation. 
 
Indeed, we found that turning off multipolygon path simplification just before the call to_polygons() did the trick:
 
we find that multipolygons now preserve all of the vertices that define them -- in some cases in excess of 10K points.
 
Thanks so much for pointing us in the right direction. 
 
Mark 
 
On 09/13/11, Benjamin Root <ben...@ou...> wrote:
> 
> 
> On Tue, Sep 13, 2011 at 1:02 PM, Leidner, Mark <mle...@ae...> wrote:
> 
> 
> > 
> > Ben,
> > 
> > 
> > Good to hear from you.
> > 
> > 
> > We are using matplotlib v1.0.1_5 on an install from Macports.
> > 
> > 
> > Hearing that there is simplification logic is very intriguing.
> > 
> > 
> > 
> > Mark
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> 
> 
> Try this and tell me if the results are better. Right before the line where you call to_polygons(), add this line:
> 
> multipolygon.should_simplify = False
> 
> The simplification logic gets triggered automatically if the rcParam['path.simplify'] is True and if there are more them 128 vertices and those vertices are all simple LINETO segments. I think in your situation, this is true. So, we can force a non-simplification directly like above, or set your rcParams file with path.simplify to False (but this may make graph rendering significantly slower and more resource intensive overall).
> 
> The path simplification logic is designed so that one does not see any visual differences, however, there might need to be some additional logic for those who are accessing the path directly.
> 
> I hope this helps!
> Ben Root
> 
> 
> 
> 
> 
 
From: questions a. <que...@gm...> - 2011年10月05日 04:21:08
thank you! of course!
On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing <ef...@ha...> wrote:
> On 10/04/2011 05:40 PM, questions anon wrote:
> > Excellent, thank you. That works for both quiver and barb.
> > In regards to the shape that has to do with the netcdf file, wind
> > direction variable also has lat and lon. I ended up needing to slice so
> > I could skip a few points otherwise there was too many arrows on the map.
> > Below is the code that worked in case someone else needs help.
>
> Are you sure it worked correctly? I don't think so. See below.
>
> > Thanks again
> >
> > from netCDF4 import Dataset
> > import numpy as N
> > import pylab as plt
> > from numpy import ma as MA
> > from mpl_toolkits.basemap import Basemap
> > import os
> >
> > ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc',
> > 'r+', 'NETCDF4')
> > WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
>
> Don't you need to convert from degrees to radians? sin and cos (used
> below) expect radians, not degrees. You can use N.deg2rad(WDIR) to
> convert.
>
> > LAT=ncfile.variables['latitude'][0::5]
> > LON=ncfile.variables['longitude'][0::5]
> > TIME=ncfile.variables['time'][20]
> > ncfile.close()
> >
> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> > llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> > x,y=map(*N.meshgrid(LON,LAT))
> > u=1*N.sin(WDIR)
> > v=1*N.cos(WDIR)
> > map.quiver(x,y,u, v)
>
> Assuming you do convert to radians the above will work for your mercator
> projection but it will not align the vectors correctly with respect to
> the parallels and meridians for other projections, so you should use
> map.rotate_vector as in the basemap quiver demo.
>
> Eric
>
>
> >
> > # otherwise use the barb tool - map.barbs(x,y,u, v)
> >
> > plt.title('Wind Direction')
> > plt.show()
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Eric F. <ef...@ha...> - 2011年10月05日 04:09:03
On 10/04/2011 05:40 PM, questions anon wrote:
> Excellent, thank you. That works for both quiver and barb.
> In regards to the shape that has to do with the netcdf file, wind
> direction variable also has lat and lon. I ended up needing to slice so
> I could skip a few points otherwise there was too many arrows on the map.
> Below is the code that worked in case someone else needs help.
Are you sure it worked correctly? I don't think so. See below.
> Thanks again
>
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc',
> 'r+', 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
Don't you need to convert from degrees to radians? sin and cos (used 
below) expect radians, not degrees. You can use N.deg2rad(WDIR) to convert.
> LAT=ncfile.variables['latitude'][0::5]
> LON=ncfile.variables['longitude'][0::5]
> TIME=ncfile.variables['time'][20]
> ncfile.close()
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=map(*N.meshgrid(LON,LAT))
> u=1*N.sin(WDIR)
> v=1*N.cos(WDIR)
> map.quiver(x,y,u, v)
Assuming you do convert to radians the above will work for your mercator 
projection but it will not align the vectors correctly with respect to 
the parallels and meridians for other projections, so you should use 
map.rotate_vector as in the basemap quiver demo.
Eric
>
> # otherwise use the barb tool - map.barbs(x,y,u, v)
>
> plt.title('Wind Direction')
> plt.show()
From: questions a. <que...@gm...> - 2011年10月05日 03:40:32
Excellent, thank you. That works for both quiver and barb.
In regards to the shape that has to do with the netcdf file, wind direction
variable also has lat and lon. I ended up needing to slice so I could skip a
few points otherwise there was too many arrows on the map.
Below is the code that worked in case someone else needs help.
Thanks again
from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
LAT=ncfile.variables['latitude'][0::5]
LON=ncfile.variables['longitude'][0::5]
TIME=ncfile.variables['time'][20]
ncfile.close()
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
 llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=map(*N.meshgrid(LON,LAT))
u=1*N.sin(WDIR)
v=1*N.cos(WDIR)
map.quiver(x,y,u, v)
# otherwise use the barb tool - map.barbs(x,y,u, v)
plt.title('Wind Direction')
plt.show()
On Wed, Oct 5, 2011 at 2:00 PM, Ethan Gutmann <eth...@gm...>wrote:
> Anon,
> I don't know the quiver routine, but u and v are usually vectors for the
> wind speed in the east-west and north south directions. As such they should
> not be equal to lat and lon (*10), as you are doing, but rather should be
> windspeed * sin(direction) and windspeed*cos(direction). If you don't have
> windspeed or want them all to be the same size arrows, just substitute 1 for
> windspeed (or 10 if you want longer arrows)
>
> You shouldn't have to "set" north,south,east,west, etc. generally North is
> 0, South is 180, etc, so that should all be assigned already.
>
> It also looks like you have an array size mis-match, can you print
> LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon
> variables also need to be subset to [-50]?
>
> hope this helps,
> Ethan
>
> On Oct 4, 2011, at 5:58 PM, questions anon wrote:
>
> Thanks for responding. I believe quiver is more appropriate because I am
> only using wind direction (at this stage) and this results in arrows.
> I have had a look at the demos and still do not understand how to plot my
> degrees in arrows. How do I define which angle is north, south, west, east,
> etc?
> Any suggestions? Thanks
>
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> LAT=ncfile.variables['latitude'][:]
> LON=ncfile.variables['longitude'][:]
> TIME=ncfile.variables['time'][-50]
> ncfile.close()
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=LON,LAT
> u=10*x
> v=10*y
> map.quiver(x,y,u, v, WDIR)
> plt.title('Wind Direction')
> plt.show()
>
>
> Traceback (most recent call last):
> File "d:/plot_winddirection.py", line 22, in <module>
> map.quiver(x,y,u, v, WDIR)
> File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
> line 3102, in quiver
> ret = ax.quiver(x,y,u,v,*args,**kwargs)
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6320, in
> quiver
> q = mquiver.Quiver(self, *args, **kw)
> File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 395, in
> __init__
> self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
> File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 270,
> in hstack
> return _nx.concatenate(map(atleast_1d,tup),1)
> ValueError: array dimensions must agree except for d_0
>
>
>
> On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <ef...@ha...> wrote:
>
>> On 10/03/2011 03:00 PM, Benjamin Root wrote:
>> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon <
>> que...@gm...
>> > <mailto:que...@gm...>> wrote:
>> >
>> > Hi All,
>> > Is there a simple way to plot a directional arrow to represent a
>> degree?
>> > I have a netcdf file containing wind direction as degrees and I
>> > would like to make a plot with all little arrows representing the
>> > wind direction.
>> > Below is the code I am using currently to plot wind direction but am
>> > not sure where/how to add directional arrows.
>> > Thanks
>> >
>> >
>> > from netCDF4 import Dataset
>> > import numpy as N
>> > import pylab as plt
>> > from numpy import ma as MA
>> > from mpl_toolkits.basemap import Basemap
>> > import os
>> >
>> > ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
>> > 'NETCDF4')
>> > WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
>> > LAT=ncfile.variables['latitude'][:]
>> > LON=ncfile.variables['longitude'][:]
>> > TIME=ncfile.variables['time'][-50]
>> > fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
>> > WDIR=MA.masked_values(WDIR, fillvalue)
>> > ncfile.close()
>> >
>> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>> >
>> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
>> > x,y=map(*N.meshgrid(LON,LAT))
>> > map.drawstates()
>> > map.drawcoastlines()
>> > plt.title('Wind Direction')
>> > CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
>> > l,b,w,h =0.1,0.1,0.8,0.8
>> > cax = plt.axes([l+w+0.025, b, 0.025, h])
>> > plt.colorbar(CS,cax=cax,drawedges=True)
>> > plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
>> > plt.show()
>> >
>> >
>> > Would the barb() command do what you want?
>> >
>> >
>> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
>> >
>> http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
>> >
>> > They aren't arrows, but they are commonly used in meteorology to plot
>> > windfields.
>> >
>> > Cheers,
>> > Ben Root
>>
>> There is also quiver, both in matplotlib and in basemap. See the
>> quiver_demo.py and barb_demo.py in the basemap examples directory.
>>
>> Eric
>>
>> >
>> >
>> >
>> >
>> ------------------------------------------------------------------------------
>> > All the data continuously generated in your IT infrastructure contains a
>> > definitive record of customers, application performance, security
>> > threats, fraudulent activity and more. Splunk takes this data and makes
>> > sense of it. Business sense. IT sense. Common sense.
>> > http://p.sf.net/sfu/splunk-d2dcopy1
>> >
>> >
>> >
>> > _______________________________________________
>> > Matplotlib-users mailing list
>> > Mat...@li...
>> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>>
>> ------------------------------------------------------------------------------
>> All the data continuously generated in your IT infrastructure contains a
>> definitive record of customers, application performance, security
>> threats, fraudulent activity and more. Splunk takes this data and makes
>> sense of it. Business sense. IT sense. Common sense.
>> http://p.sf.net/sfu/splunk-d2dcopy1
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
>
> http://p.sf.net/sfu/splunk-d2dcopy1_______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
From: Ryan N. <rne...@gm...> - 2011年10月05日 03:14:38
Mike,
You may want to look into the matplotlib.cm and matplotlib.colors modules.
I've had good success with matplotlib.colors.LinearSegmentedColormap and its
'from_list' method. The documentation is the best location for information
on this topic. If you have a large number of locations, then the color
differences will be pretty small, unless you use a colormap with lots of
different colors. Below is your example using the 'from_list' method and the
built-in colormap 'hsv' (you'll just have to flip around the comments). For
the matplotlib.cm colormaps, be sure to passed in normalized values (which
is why the call to the colormap is slightly complex).
Maybe this is a bit more help.
Ryan
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as plc
import matplotlib.cm as mcm
IDs = np.array([47, 33, 47, 12, 50, 50, 27, 27, 16, 27])
locations = np.array(['201', '207', '207', '205', '204', '201', '209',
'209', \
 '207','207'])
dates = np.array([ 733315.83240741, 733315.83521991, 733315.83681713,
 733315.83788194, 733336.54554398, 733336.54731481,
 733337.99842593, 733337.99943287, 733338.00070602,
 733338.00252315])
fig = plt.figure()
ax = fig.add_subplot(111)
locs_un = np.unique(locations)
# The variable assignment below can be removed if you use the mcm module.
cs = plc.LinearSegmentedColormap.from_list('Colormap name', ['r', 'g', 'b'],
 N=len(locs_un) )
for n, i in enumerate(locs_un):
 # Reverse the comments here to use the mcm module 'hsv' colormap.
 ax.plot(dates[locations==i],IDs[locations==i],'d', c=cs(n), label=i)
 #ax.plot(dates[locations==i],IDs[locations==i],'d',
 # c=mcm.hsv( float(n)/(len(locs_un)-1) ), label=i)
ax.xaxis_date()
fig.autofmt_xdate()
plt.legend(numpoints=1)
plt.grid(True)
plt.show()
On Tue, Oct 4, 2011 at 5:25 PM, Michael Castleton <fat...@ya...>wrote:
>
> Ryan,
> I should clarify my color issue. Your code is smart enough to generate
> however many colors are needed but I want to make sure the colors are all
> unique.
> Thanks again!
>
> Mike
>
>
>
> Mike, sorry to send this twice... I should have sent it to the list as
> well...
> _______________________________
> Mike,
>
> If your locations were integers or floats rather than strings, you could
> just change the scatter call to the following:
> ax.scatter(dates,IDs,c=
> locations,marker='d')
> I don't know about a legend... I don't know if that is possible with a
> scatter plot (?). Because scatter plots get their colors based off of a
> color map, you could generate a color bar for your data. You may need to
> capture the collection object returned from the scatter plot function call,
> though. Here's your code with these modifications:
>
> # Of course, you need to change your locations list to integers rather than
> strings.
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> sc = ax.scatter(dates,IDs,c=locations,marker='d')
> ax.xaxis_date()
> fig.autofmt_xdate()
> plt.colorbar(sc)
> plt.grid(True)
> plt.show()
>
> If you really need a legend, then you could do a loop of plot commands for
> each set of unique locations. Using some fancy Numpy masking makes the
> process easier...
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> IDs = np.array([47, 33, 47, 12, 50, 50, 27, 27, 16, 27])
> locations = np.array(['201', '207', '207', '205', '204', '201', '209',
> '209', \
> '207','207'])
> dates = np.array([ 733315.83240741, 733315.83521991, 733315.83681713,
>
> 733315.83788194, 733336.54554398, 733336.54731481,
> 733337.99842593, 733337.99943287, 733338.00070602,
> 733338.00252315])
>
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> cs = ['r', 'b', 'g', 'k', 'c']
> for n, i in enumerate(np.unique(locations)):
> ax.plot(dates[locations==i],IDs[locations==i],'d', c=cs[n%len(cs)],
> label=i)
> ax.xaxis_date()
> fig.autofmt_xdate()
> plt.legend(numpoints=1)
> plt.grid(True)
> plt.show()
>
> Not sure if this is exactly what you wanted, but I hope it helps a little.
>
> Ryan
>
>
>
> --
> View this message in context:
> http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32592799.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Ethan G. <eth...@gm...> - 2011年10月05日 03:01:04
Anon, 
I don't know the quiver routine, but u and v are usually vectors for the wind speed in the east-west and north south directions. As such they should not be equal to lat and lon (*10), as you are doing, but rather should be windspeed * sin(direction) and windspeed*cos(direction). If you don't have windspeed or want them all to be the same size arrows, just substitute 1 for windspeed (or 10 if you want longer arrows)
You shouldn't have to "set" north,south,east,west, etc. generally North is 0, South is 180, etc, so that should all be assigned already. 
It also looks like you have an array size mis-match, can you print LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon variables also need to be subset to [-50]? 
hope this helps,
Ethan
On Oct 4, 2011, at 5:58 PM, questions anon wrote:
> Thanks for responding. I believe quiver is more appropriate because I am only using wind direction (at this stage) and this results in arrows. 
> I have had a look at the demos and still do not understand how to plot my degrees in arrows. How do I define which angle is north, south, west, east, etc?
> Any suggestions? Thanks
> 
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
> 
> ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+', 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> LAT=ncfile.variables['latitude'][:]
> LON=ncfile.variables['longitude'][:]
> TIME=ncfile.variables['time'][-50]
> ncfile.close()
> 
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=LON,LAT
> u=10*x
> v=10*y
> map.quiver(x,y,u, v, WDIR)
> plt.title('Wind Direction')
> plt.show()
> 
> 
> Traceback (most recent call last):
> File "d:/plot_winddirection.py", line 22, in <module>
> map.quiver(x,y,u, v, WDIR)
> File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 3102, in quiver
> ret = ax.quiver(x,y,u,v,*args,**kwargs)
> File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6320, in quiver
> q = mquiver.Quiver(self, *args, **kw)
> File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 395, in __init__
> self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
> File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 270, in hstack
> return _nx.concatenate(map(atleast_1d,tup),1)
> ValueError: array dimensions must agree except for d_0
> 
> 
> 
> On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <ef...@ha...> wrote:
> On 10/03/2011 03:00 PM, Benjamin Root wrote:
> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon <que...@gm...
> > <mailto:que...@gm...>> wrote:
> >
> > Hi All,
> > Is there a simple way to plot a directional arrow to represent a degree?
> > I have a netcdf file containing wind direction as degrees and I
> > would like to make a plot with all little arrows representing the
> > wind direction.
> > Below is the code I am using currently to plot wind direction but am
> > not sure where/how to add directional arrows.
> > Thanks
> >
> >
> > from netCDF4 import Dataset
> > import numpy as N
> > import pylab as plt
> > from numpy import ma as MA
> > from mpl_toolkits.basemap import Basemap
> > import os
> >
> > ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> > 'NETCDF4')
> > WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> > LAT=ncfile.variables['latitude'][:]
> > LON=ncfile.variables['longitude'][:]
> > TIME=ncfile.variables['time'][-50]
> > fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
> > WDIR=MA.masked_values(WDIR, fillvalue)
> > ncfile.close()
> >
> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> > llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> > x,y=map(*N.meshgrid(LON,LAT))
> > map.drawstates()
> > map.drawcoastlines()
> > plt.title('Wind Direction')
> > CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
> > l,b,w,h =0.1,0.1,0.8,0.8
> > cax = plt.axes([l+w+0.025, b, 0.025, h])
> > plt.colorbar(CS,cax=cax,drawedges=True)
> > plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
> > plt.show()
> >
> >
> > Would the barb() command do what you want?
> >
> > http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
> > http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
> >
> > They aren't arrows, but they are commonly used in meteorology to plot
> > windfields.
> >
> > Cheers,
> > Ben Root
> 
> There is also quiver, both in matplotlib and in basemap. See the
> quiver_demo.py and barb_demo.py in the basemap examples directory.
> 
> Eric
> 
> >
> >
> >
> > ------------------------------------------------------------------------------
> > All the data continuously generated in your IT infrastructure contains a
> > definitive record of customers, application performance, security
> > threats, fraudulent activity and more. Splunk takes this data and makes
> > sense of it. Business sense. IT sense. Common sense.
> > http://p.sf.net/sfu/splunk-d2dcopy1
> >
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1_______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: mdekauwe <mde...@gm...> - 2011年10月05日 02:50:53
For those interested things are defined differently.
ax.axis["bottom"].major_ticklabels.set_pad(10)
ax.axis["bottom"].label.set_pad(15)
ax.axis["bottom"].major_ticklabels.set_rotation(30)
explained well here
(http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/axisartist.html#axisartist-manual),
i missed this!
Still haven't worked out the bold but I am sure there will be something on
that page
-- 
View this message in context: http://old.nabble.com/rotating-x-tick-labels%2C-bold-labels-with-axislines-toolkit----tp32593701p32593884.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: mdekauwe <mde...@gm...> - 2011年10月05日 01:32:37
Hi,
I can't seem to combine the ability to rotate labels and make labels bold
when I use the axislines toolkit
(http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/axislines.html).
Is there a way to make this work? 
e.g. the below script does not rotate the xtick labels or make the label
bold.
thanks,
Martin
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import Subplot
import numpy as np
fig = plt.figure()
ax = Subplot(fig, 111)
fig.add_subplot(ax)
ax.axis["right"].set_visible(False)
ax.axis["top"].set_visible(False)
ax.plot(np.arange(10))
xl = np.arange(10) * 2
xl = [str(i) for i in xl]
ax.set_xticks(np.arange(len(xl)))
ax.set_xticklabels(xl, rotation=30)
xlabels = ax.get_xticklabels()
for label in xlabels:
 label.set_rotation(45)
ax.set_xlabel("Test", fontweight="bold")
plt.show()
-- 
View this message in context: http://old.nabble.com/rotating-x-tick-labels%2C-bold-labels-with-axislines-toolkit----tp32593701p32593701.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Michael C. <fat...@ya...> - 2011年10月05日 00:13:49
John,
I'll give this method a try also.
Thanks for the ideas!
Mike
John Ladasky-3 wrote:
> 
> On Mon, 2011年10月03日 at 12:49 -0700, Michael Castleton wrote:
>> Hello,
>> I am using Matplotlib 1.0.0 in Python 2.6.
>> I am trying to plot time series data of unique IDs and color the points
>> based on location. Each data point has a unique ID value, a date value,
>> and
>> a location value.
>> The unique IDs and date values are plotting fine but I am unable to
>> control
>> the color and subsequently the legend.
> 
>> I've been trying to figure out how to set color = locations with no
>> success.
>> Any ideas out there?
> 
> Michael, if I were you, I would reorganize and group your data into
> several separate scatter data sets, based on the location parameter.
> Then, color each SET the color that you want. Here's a start, from the
> data as you provided it:
> 
>>>> points = [(a, b, c) for a, b, c in zip(locations, IDs, dates)]
>>>> for p in points:
> print p
> 
> ('201', 47, 733315.83240741002)
> ('207', 33, 733315.83521991002)
> ('207', 47, 733315.83681712998)
> ('205', 12, 733315.83788193995)
> ('204', 50, 733336.54554397997)
> ('201', 50, 733336.54731480998)
> ('209', 27, 733337.99842593004)
> ('209', 27, 733337.99943286995)
> ('207', 16, 733338.00070602004)
> ('207', 27, 733338.00252314995)
> 
>>>> def make_dict(lst):
> d = {}
> for a, b, c in lst:
> 	 try:
> d[a][0].append(b)
> d[a][1].append(c)
> except KeyError:
> d[a] = ([b],[c])
> return d
> 
>>>> collated = make_dict(points)
>>>> for k in collated:
> print k, collated[k]
> 
> 201 ([47, 50], [733315.83240741002, 733336.54731480998])
> 209 ([27, 27], [733337.99842593004, 733337.99943286995])
> 205 ([12], [733315.83788193995])
> 204 ([50], [733336.54554397997])
> 207 ([33, 47, 16, 27], [733315.83521991002, 733315.83681712998,
> 733338.00070602004, 733338.00252314995])
> 
>>From collated, you could then plot five scattergrams, each of a
> different color, in the same axes object.
> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32593466.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Showing 12 results of 12

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 によって変換されたページ (->オリジナル) /