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) |
|
|
|
|
|
|
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.
|
|
From: questions a. <que...@gm...> - 2011-10-04 23:58:29
|
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
>
|
|
From: Michael C. <fat...@ya...> - 2011-10-04 22:25:09
|
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.
|
|
From: Michael C. <fat...@ya...> - 2011-10-04 21:58:05
|
Ryan,
I have tried setting c=locations (after converting to float) and gotten
inconsistent results. For a dataset with ~32,000 points it seems to work,
but a 2nd dataset of ~100,000 points colors everything the same even though
there are at least 10 locations.
Your second idea works nicely and I'm going to try applying it to my data.
The only real issue is that I don't know how many locations there will be
for each plot so I can't hard code the colors list. I think I can figure
that part out though.
Thanks!
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-tp32584727p32592621.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|
|
From: Jens N. <JN...@Ro...> - 2011-10-04 14:15:24
|
Hi Nils. I have never tried to do a real printout, so I am no expert here. My use case was almost always to directly create pdf or ps documents, which can be done nicely using the several print_* methods of the figurecanvas. You can use Actions for your case instead of a widget. Actually they should considered to be recommended when using Qt4. Actions are a very elegant way to attach functionality to a program. So define an action like you suggested, and add it to the toolbar using the addAction method of the toolbar. Then you might want to implement a slot, that you in turn connect to the "triggered" signal of your action, which implements the real printing. I can't really help you with the printing itself, but have found an implemented strategy after a bit googling. That might be a start ... http://gotm.git.sourceforge.net/git/gitweb.cgi?p=gotm/gotm;a=blob;f=gui.py/xmlplot/gui_qt4.py;h=6e0239a958580ac2a35cd26653d83f26909fda24;hb=163207fa3fcc86f91008056c77e9c31fd6a9e246 Have a look at the onPrint method here. Hoping again that this was helpful. Jens -----Original Message----- From: Nils Wagner [mailto:nw...@ia...] Sent: Tuesday, October 04, 2011 11:08 AM To: Jens Nie Cc: mat...@li... Subject: Re: [Matplotlib-users] Customizing the Navigation toolbar On Tue, 4 Oct 2011 10:09:57 +0200 Jens Nie <JN...@Ro...> wrote: > Hi Nils. > > The Qt based Navigation toolbar is just a Qt Widget with a proper >layout already set. So you should be able to add any Qt widget to the >toolbar using its addWidget method. > I was able to add a simple line edit (without any use) like so: > > import sys > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > from matplotlib.figure import Figure > from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as >FigureCanvas from matplotlib.backends.backend_qt4agg import >NavigationToolbar2QT as NavigationToolbar2 > > class ViewWidget(QMainWindow): > def __init__(self): > QMainWindow.__init__(self) > > # create a simple main widget to keep the figure > self.mainWidget = QWidget() > self.setCentralWidget(self.mainWidget) > > layout = QVBoxLayout() > self.mainWidget.setLayout(layout) > > # create a figure > self.figure_canvas = FigureCanvas(Figure()) > layout.addWidget(self.figure_canvas, 10) > > # and the axes for the figure > self.axes = >self.figure_canvas.figure.add_subplot(111) > > # add a navigation toolbar > self.navigation_toolbar = >NavigationToolbar2(self.figure_canvas, self) > layout.addWidget(self.navigation_toolbar, 0) > > # create a simple widget to extend the navigation toolbar > anotherWidget=QLineEdit() > # add the new widget to the existing navigation toolbar > self.navigation_toolbar.addWidget(anotherWidget) > > if __name__=="__main__": > app=QApplication(sys.argv) > mw=ViewWidget() > mw.show() > sys.exit(app.exec_()) > > Hope that helps ... > > Best regards > > Jens > Hi Jens, Thank you very much for your response. Hence I have tried import sys import numpy as np from PyQt4.QtCore import * from PyQt4.QtGui import * from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2 class ViewWidget(QMainWindow): def __init__(self): QMainWindow.__init__(self) # create a simple main widget to keep the figure self.mainWidget = QWidget() self.setCentralWidget(self.mainWidget) layout = QVBoxLayout() self.mainWidget.setLayout(layout) # create a figure self.figure_canvas = FigureCanvas(Figure()) layout.addWidget(self.figure_canvas, 10) # and the axes for the figure self.axes = self.figure_canvas.figure.add_subplot(111) x = np.linspace(0.,2*np.pi,100) self.axes.plot(x,np.sin(x)) # add a navigation toolbar self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self) layout.addWidget(self.navigation_toolbar, 0) # create a simple widget to extend the navigation toolbar # anotherWidget=QLineEdit() printer = QPrinter() anotherWidget= QPrintDialog(printer,self) # add the new widget to the existing navigation toolbar self.navigation_toolbar.addWidget(anotherWidget) if __name__=="__main__": app=QApplication(sys.argv) mw=ViewWidget() mw.show() sys.exit(app.exec_()) How do I connect the plot with the printer ? How can I replace the printer dialog by a small icon ? I found the lines a = self.addAction(self._icon('filesave.svg'), 'Save', self.save_figure) in backend_qt4.py Nils ------------------------------------------------------------------------------ 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: John L. <joh...@sb...> - 2011-10-04 09:09:56
|
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.
|
|
From: Nils W. <nw...@ia...> - 2011-10-04 09:08:25
|
On Tue, 4 Oct 2011 10:09:57 +0200
Jens Nie <JN...@Ro...> wrote:
> Hi Nils.
>
> The Qt based Navigation toolbar is just a Qt Widget with
>a proper layout already set. So you should be able to add
>any Qt widget to the toolbar using its addWidget method.
> I was able to add a simple line edit (without any use)
>like so:
>
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import
>FigureCanvasQTAgg as FigureCanvas
> from matplotlib.backends.backend_qt4agg import
>NavigationToolbar2QT as NavigationToolbar2
>
> class ViewWidget(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self)
>
> # create a simple main widget to keep the figure
> self.mainWidget = QWidget()
> self.setCentralWidget(self.mainWidget)
>
> layout = QVBoxLayout()
> self.mainWidget.setLayout(layout)
>
> # create a figure
> self.figure_canvas = FigureCanvas(Figure())
> layout.addWidget(self.figure_canvas, 10)
>
> # and the axes for the figure
> self.axes =
>self.figure_canvas.figure.add_subplot(111)
>
> # add a navigation toolbar
> self.navigation_toolbar =
>NavigationToolbar2(self.figure_canvas, self)
> layout.addWidget(self.navigation_toolbar, 0)
>
> # create a simple widget to extend the navigation
>toolbar
> anotherWidget=QLineEdit()
> # add the new widget to the existing navigation
>toolbar
> self.navigation_toolbar.addWidget(anotherWidget)
>
> if __name__=="__main__":
> app=QApplication(sys.argv)
> mw=ViewWidget()
> mw.show()
> sys.exit(app.exec_())
>
> Hope that helps ...
>
> Best regards
>
> Jens
>
Hi Jens,
Thank you very much for your response.
Hence I have tried
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import
FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import
NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
# create a simple main widget to keep the figure
self.mainWidget = QWidget()
self.setCentralWidget(self.mainWidget)
layout = QVBoxLayout()
self.mainWidget.setLayout(layout)
# create a figure
self.figure_canvas = FigureCanvas(Figure())
layout.addWidget(self.figure_canvas, 10)
# and the axes for the figure
self.axes =
self.figure_canvas.figure.add_subplot(111)
x = np.linspace(0.,2*np.pi,100)
self.axes.plot(x,np.sin(x))
# add a navigation toolbar
self.navigation_toolbar =
NavigationToolbar2(self.figure_canvas, self)
layout.addWidget(self.navigation_toolbar, 0)
# create a simple widget to extend the navigation
toolbar
# anotherWidget=QLineEdit()
printer = QPrinter()
anotherWidget= QPrintDialog(printer,self)
# add the new widget to the existing navigation
toolbar
self.navigation_toolbar.addWidget(anotherWidget)
if __name__=="__main__":
app=QApplication(sys.argv)
mw=ViewWidget()
mw.show()
sys.exit(app.exec_())
How do I connect the plot with the printer ?
How can I replace the printer dialog by a small icon ?
I found the lines
a = self.addAction(self._icon('filesave.svg'),
'Save',
self.save_figure)
in backend_qt4.py
Nils
|
|
From: Jens N. <JN...@Ro...> - 2011-10-04 08:30:46
|
Hi Nils.
The Qt based Navigation toolbar is just a Qt Widget with a proper layout already set. So you should be able to add any Qt widget to the toolbar using its addWidget method.
I was able to add a simple line edit (without any use) like so:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
# create a simple main widget to keep the figure
self.mainWidget = QWidget()
self.setCentralWidget(self.mainWidget)
layout = QVBoxLayout()
self.mainWidget.setLayout(layout)
# create a figure
self.figure_canvas = FigureCanvas(Figure())
layout.addWidget(self.figure_canvas, 10)
# and the axes for the figure
self.axes = self.figure_canvas.figure.add_subplot(111)
# add a navigation toolbar
self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)
layout.addWidget(self.navigation_toolbar, 0)
# create a simple widget to extend the navigation toolbar
anotherWidget=QLineEdit()
# add the new widget to the existing navigation toolbar
self.navigation_toolbar.addWidget(anotherWidget)
if __name__=="__main__":
app=QApplication(sys.argv)
mw=ViewWidget()
mw.show()
sys.exit(app.exec_())
Hope that helps ...
Best regards
Jens
-----Original Message-----
From: Nils Wagner [mailto:nw...@ia...]
Sent: Thursday, September 29, 2011 2:56 PM
To: mat...@li...
Subject: [Matplotlib-users] Customizing the Navigation toolbar
Hi all,
How can I add a printer button to the Navigation toolbar http://matplotlib.sourceforge.net/users/navigation_toolbar.html
?
A small example for QT would be awesome.
Thanks in advance.
Nils
------------------------------------------------------------------------------
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-04 04:41:44
|
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
On Mon, Oct 3, 2011 at 2:49 PM, Michael Castleton <fat...@ya...>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.
>
> Here is a sample of the data.
> IDs = [47, 33, 47, 12, 50, 50, 27, 27, 16, 27]
> locations = ['201', '207', '207', '205', '204', '201', '209', '209',
> '207','207']
> dates = [ 733315.83240741, 733315.83521991, 733315.83681713,
> 733315.83788194, 733336.54554398, 733336.54731481,
> 733337.99842593, 733337.99943287, 733338.00070602,
> 733338.00252315]
>
> This basic code works.
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> ax.scatter(dates,IDs,marker='d')
> ax.xaxis_date()
> fig.autofmt_xdate()
> plt.grid(True)
> plt.show()
>
> I've been trying to figure out how to set color = locations with no
> success.
> Any ideas out there?
> Thanks,
>
> Mike
> --
> View this message in context:
> http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32584727.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: Jae-Joon L. <lee...@gm...> - 2011-10-04 02:17:34
|
On Tue, Oct 4, 2011 at 4:22 AM, Christopher Brown <c-...@as...> wrote:
> tick.label1.set_color('red')
>
You should use tick.label2, not tick.label1.
tick.label2.set_color('red')
Anyhow, as Eric said, it is strongly advised to use the tick_params method.
-JJ
|
|
From: Eric F. <ef...@ha...> - 2011-10-04 01:54:41
|
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
|
|
From: John L. <joh...@sb...> - 2011-10-04 01:11:27
|
Following up to my own post: First, Sourceforge's listserv did not like the link to my animation. Let my try again, with a shortened link: http://flic.kr/p/an4oyo Second: > The indirect nature of this redrawing-by-sizing approach > sent me on a long and pointless hunt for bugs in my own code. Putting this another way -- explicit is better than implicit! |
|
From: Benjamin R. <ben...@ou...> - 2011-10-04 01:01:04
|
On Mon, Oct 3, 2011 at 6:51 PM, questions anon <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
|
|
From: questions a. <que...@gm...> - 2011-10-03 23:51:12
|
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()
|
|
From: Eric F. <ef...@ha...> - 2011-10-03 23:14:04
|
On 10/03/2011 09:22 AM, Christopher Brown wrote:
> import matplotlib.pyplot as pp
> fig = pp.figure()
> ax1 = fig.add_subplot(111)
> ax2 = ax1.twinx()
> # works (tick labels are blue):
> for tick in ax1.yaxis.get_major_ticks():
> tick.label1.set_color('blue')
> # does not work (tick labels are not red):
> for tick in ax2.yaxis.get_major_ticks():
> tick.label1.set_color('red')
> pp.show()
Try this instead:
import matplotlib.pyplot as pp
fig = pp.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.tick_params(axis='y', labelcolor='b')
ax2.tick_params(axis='y', labelcolor='r')
pp.show()
Eric
|
|
From: Benjamin R. <ben...@ou...> - 2011-10-03 22:57:49
|
On Mon, Oct 3, 2011 at 2:22 PM, Christopher Brown <c-...@as...> wrote:
> Hi,
>
> Im running mpl 1.01 from sf installer with py2.7 on windows xp. Can
> anyone tell me what I am doing wrong in the following snippet:
>
> import matplotlib.pyplot as pp
> fig = pp.figure()
> ax1 = fig.add_subplot(111)
> ax2 = ax1.twinx()
> # works (tick labels are blue):
> for tick in ax1.yaxis.get_major_ticks():
> tick.label1.set_color('blue')
> # does not work (tick labels are not red):
> for tick in ax2.yaxis.get_major_ticks():
> tick.label1.set_color('red')
> pp.show()
>
>
Confirmed with the v1.1.x branch as well. Although, I don't play with
twinx() enough to know if this is really a bug or not, but my vote is that
it is a bug.
Ben Root
|
|
From: Christopher B. <c-...@as...> - 2011-10-03 22:21:34
|
Hi,
Im running mpl 1.01 from sf installer with py2.7 on windows xp. Can
anyone tell me what I am doing wrong in the following snippet:
import matplotlib.pyplot as pp
fig = pp.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
# works (tick labels are blue):
for tick in ax1.yaxis.get_major_ticks():
tick.label1.set_color('blue')
# does not work (tick labels are not red):
for tick in ax2.yaxis.get_major_ticks():
tick.label1.set_color('red')
pp.show()
--
Christopher Brown, Ph.D.
Associate Research Professor
Department of Speech and Hearing Science
Arizona State University
http://pal.asu.edu
|
|
From: Isidora <is...@ju...> - 2011-10-03 21:40:30
|
Hi again, still trying to accomplish the filling of certain paths only inside U.S. It ocurred to me that set_clip_path could work but so far, I have not been able to show the curve in the map. Could someone point out what is missing? Thanks #!/usr/bin/env python """http://www.scipy.org/Cookbook/Finding_Convex_Hull""" import numpy as n, pylab as p, time import matplotlib.pyplot as plt import matplotlib.patches as mpatches import matplotlib.path as mpath from matplotlib.patches import Polygon from mpl_toolkits.basemap import Basemap import sys import numpy as np import matplotlib.cm as cm def _angle_to_point(point, centre): '''calculate angle in 2-D between points and x axis''' delta = point - centre res = n.arctan(delta[1] / delta[0]) if delta[0] < 0: res += n.pi return res def _draw_triangle(p1, p2, p3, **kwargs): tmp = n.vstack((p1,p2,p3)) x,y = [x[0] for x in zip(tmp.transpose())] p.fill(x,y, **kwargs) # commented out to see result def area_of_triangle(p1, p2, p3): '''calculate area of any triangle given co-ordinates of the corners''' return n.linalg.norm(n.cross((p2 - p1), (p3 - p1)))/2. def convex_hull(points, graphic=True, smidgen=0.0075): '''Calculate subset of points that make a convex hull around points Recursively eliminates points that lie inside two neighbouring points until only convex hull is remaining. :Parameters: points : ndarray (2 x m) array of points for which to find hull graphic : bool use pylab to show progress? smidgen : float offset for graphic number labels - useful values depend on your data range :Returns: hull_points : ndarray (2 x n) convex hull surrounding points ''' # Commenting these 2 lines out shows the plotting of the country border # if graphic: # p.clf() n_pts = points.shape[1] print "POINTS shape[1]:%d" %(n_pts) assert(n_pts > 5) centre = points.mean(1) angles = n.apply_along_axis(_angle_to_point, 0, points, centre) pts_ord = points[:,angles.argsort()] pts = [x[0] for x in zip(pts_ord.transpose())] prev_pts = len(pts) + 1 k = 0 while prev_pts > n_pts: prev_pts = n_pts n_pts = len(pts) if graphic: p.gca().patches = [] i = -2 while i < (n_pts - 2): Aij = area_of_triangle(centre, pts[i], pts[(i + 1) % n_pts]) Ajk = area_of_triangle(centre, pts[(i + 1) % n_pts], \ pts[(i + 2) % n_pts]) Aik = area_of_triangle(centre, pts[i], pts[(i + 2) % n_pts]) if Aij + Ajk < Aik: if graphic: p.plot((pts[i + 1][0],),(pts[i + 1][1],)) # without green circle marker del pts[i+1] i += 1 n_pts = len(pts) k += 1 return n.asarray(pts) if __name__ == "__main__": x1 = -124. x2 = -57. y1 = 18. y2 = 51. m = Basemap(resolution='i',projection='stere', lat_0=39., lon_0=-98.,llcrnrlat=y1,urcrnrlat=y2,llcrnrlon=x1,urcrnrlon=x2) point0 = [] point1 = [] cpaths = (m.drawcountries()).get_paths() for cpath in cpaths: vs = cpath.vertices for v in vs: x=v[0] y=v[1] point0.append(x) point1.append(y) nonumpy = [] nonumpy.append(point0) nonumpy.append(point1) points = n.array(nonumpy) hull_pts = convex_hull(points) poly = Polygon(hull_pts) USpath = poly.get_path() USpatch = mpatches.PathPatch(USpath,facecolor='none',edgecolor='none') ax = plt.gca() ax.add_patch(USpatch) # Add my curve Path = mpath.Path pathdata = [] pathdata.append((Path.MOVETO,m(-120.,35.))) pathdata.append((Path.LINETO,m(-100.,35.))) pathdata.append((Path.LINETO,m(-100.,30.))) pathdata.append((Path.LINETO,m(-90.,28.))) pathdata.append((Path.LINETO,m(-90,25))) pathdata.append((Path.LINETO,m(-100,25))) pathdata.append((Path.CURVE3,m(-120.,35.))) codes,verts = zip(*pathdata) im = ax.imshow(verts,cmap=cm.gray,clip_path=USpatch,clip_on=True) im.set_clip_path(USpatch) m.drawparallels(np.arange(20,60,5),labels=[1,0,0,0],color='black') m.drawmeridians(np.arange(-140,60,10),labels=[0,0,0,1],color='black') plt.gcf().savefig('./ch.png') |
|
From: John L. <joh...@sb...> - 2011-10-03 21:09:04
|
Hi, folks, I will be posting this question to both matplotlib-users and wxpython-users. Apologies to those of you who have to endure my ramblings two times in a row! Using this example by John Bender, http://www.scipy.org/Matplotlib_figure_in_a_wx_panel I recently constructed a working, animated matplotlib graph in a wxPython frame. A sample output is here: http://www.flickr.com/photos/15579975@N00/6145518550 In that example, the text block is in wxPython, and the color bar for the graph's Z scale is a bitmap object which is again handled by wx. Only the live graph is rendered by matplotlib. Once I accomplished this, I attempted a more complicated, multiple-subplot display, this time with the text boxes handled my matplotlib rather than wx. I also tried removing parts of Mr. Bender's code that I thought that I would not need. Specifically, I've disabled resizing of my matplotlib panel. But when I removed the code associated with sizing, I discovered that my animation disappeared. The first frame would draw, then nothing. Digging deeper, I learned that redrawing is SOMEHOW accomplished in the PlotPanel._SetSize method. _SetSize is called when there's a wx.IDLE message. In _SetSize, you have to call PlotPanel.SetSize (note, no underscore this time) and FigureCanvasWxAgg.SetSize on EVERY cycle to make animation work. The matplotlib figure.set_size method needs only to be called the first time -- at least, in my case, where I've disabled resizing. I haven't tested a resizable window. Here are my questions. 1) I do not recall seeing this kind of behavior in wxPython before. Why does wxPython treat matplotlib objects differently? 2) How exactly is sizing making the redrawing happen? Is this a good method to use? The indirect nature of this redrawing-by-sizing approach sent me on a long and pointless hunt for bugs in my own code. Finally, how can I determine how MUCH redrawing is taking place on my matplotlib canvas? I am trying to implement eight image plots simultaneously, with some overlaid contours, and some live text, too. But sometimes I only have to update four of the eight plots, or just the text. Does matplotlib know which parts of its image are "dirty" and confine its updates appropriately? Many thanks for your insights! |
|
From: Michael C. <fat...@ya...> - 2011-10-03 19:50:05
|
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.
Here is a sample of the data.
IDs = [47, 33, 47, 12, 50, 50, 27, 27, 16, 27]
locations = ['201', '207', '207', '205', '204', '201', '209', '209',
'207','207']
dates = [ 733315.83240741, 733315.83521991, 733315.83681713,
733315.83788194, 733336.54554398, 733336.54731481,
733337.99842593, 733337.99943287, 733338.00070602,
733338.00252315]
This basic code works.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(dates,IDs,marker='d')
ax.xaxis_date()
fig.autofmt_xdate()
plt.grid(True)
plt.show()
I've been trying to figure out how to set color = locations with no success.
Any ideas out there?
Thanks,
Mike
--
View this message in context: http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32584727.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|
|
From: Benjamin R. <ben...@ou...> - 2011-10-03 13:27:15
|
> Does the installation page needs updating? > http://matplotlib.sourceforge.net/users/installing.html#building-on-osx Yes. I made several changes to those docs for the v1.1.0 release. Hopefully, it will make things clearer. Ben Root |
|
From: Gavin K. <gav...@gm...> - 2011-10-03 05:37:42
|
Dear Scott & Bryan, Thanks for the advice! Neither the dmg nor the supposedly 32bit egg on sourceforge worked for me, even after I deleted 64bit Python 2.7.2. @Bryan: Thanks for suggesting MacPorts: I didn't know about that and you are right that that would have been a good solution. Here is how I solved it (with serious help from a friend): The problem seems to be that tcl/tk on MacOSX is 32bit, which is why there is no 64bit Mac distribution on sourceforge. I downloaded the source from sourceforge (matplotlib_1.0.1.tar.gz) then expanded it into a temp directory. In the root directory, cp setupext.py.template setup.py I uncommented line 11 basedir=/usr and changed it to basedir=/usr/X11 Then in setupext.py, line 832, I removed [-2] (as suggested by old.nabble.com/Can't-install-from-PyPi-td32404788.html) Then "python setup.py install" (do not use "build"). And that was all done. Another solution might be to build 64bit Tcl/Tk on MacOSX. Instructions are here: http://buffalothedestroyer.blogspot.com/2009/07/installing-64-bit-tcltk-on-mac-os-x.html http://bugs.python.org/issue6441 but I have not tried this and it seems like this solution needs python to be rebuilt as well. Does the installation page needs updating? http://matplotlib.sourceforge.net/users/installing.html#building-on-osx I'm copying this e-mail to the list so it is archived. Gavin. On 2 October 2011 23:05, Scott Lasley <sl...@sp...> wrote: > > On Oct 2, 2011, at 9:10 AM, Gavin Koh wrote: > >> Dear all, >> >> Just installed Python 2.7.2 on my Mac running OSX 10.6. Installed >> numpy 1.6.1 and scipy 0.9.0 both from the dmg's downloaded from scipy. >> Just tried to install matplotlib but there is no 64bit dmg available. >> Tried installing from the egg instead, but that doesn't help. >> Am getting >> ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib-1.0.1_r0-py2.7-macosx-10.3-fat.egg/matplotlib/_path.so, >> 2): no suitable image found. Did find: >> /Library/Python/2.7/site-packages/matplotlib-1.0.1_r0-py2.7-macosx-10.3-fat.egg/matplotlib/_path.so: >> no matching architecture in universal wrapper >> Trying to build from source but failing desperately. Help, please? > > This site helped me to build matplotlib for OS X a while back - http://blog.hyperjeff.net/?p=160 > Since you already have python 2.7.2, numpy and scipy installed, you can probably skip down to the section on building matplotlib. Some information on the page is out of date. For example, the source is now on github at https://github.com/matplotlib/matplotlib > > I use the gfortran compiler from the R project page - http://r.research.att.com/tools/ > > I am by no means an expert at building matplotlib, but I'm happy to help if you still have problems getting it running on your mac. -- Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law. —Douglas Hofstadter (in Gödel, Escher, Bach, 1979) |