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
(5) |
3
(8) |
4
(6) |
5
(9) |
6
(7) |
7
(6) |
8
(10) |
9
(27) |
10
(7) |
11
(22) |
12
(13) |
13
(7) |
14
(4) |
15
(12) |
16
(32) |
17
(26) |
18
(14) |
19
(1) |
20
(11) |
21
(6) |
22
(11) |
23
(17) |
24
(18) |
25
(28) |
26
(11) |
27
(6) |
28
(1) |
29
(10) |
30
(12) |
|
|
|
|
De Pauw Antoine wrote: > Jeff, > > The map object is from the Basemap type, the only different thing is the > Lon,Lat and Val objects which are from the type array instead of lists > > Anyway, solutions are slowly showing themselves and I thank you all > > Have a nice day > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: It should not matter if Lon and Lat are python arrays, lists or numpy arrays. The Basemap instance __call__ method handles them all. There must be something else going on. It is always better to post actual code so we can see what is happening and test it ourselves. -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 15:29 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Thanks Jeff, >> >> This seems to work with csv file types, and I've been experimenting a bit >> with it >> >> However, when I try to implement this with my original code (with binary >> files), I get an error like that one: >> >> Traceback (most recent call last): >> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >> x,y = map(Lon,Lat) >> TypeError: 'numpy.ndarray' object is not callable >> >> I think this is coming from the fact I use array objects to store >> > values... > >> could you confirm it? >> >> > > Antoine: It looks like you the object map is not a Basemap instance, > but a numpy array. Try putting 'print type(map)' just ahead of this > statement to verify this. I suspect your re-using the name 'map' in your > code, overwriting the Basemap class instance. > > -Jeff > >> Also, I'll see if it is possible to invert color scale and mask everything >> under a certain value >> >> Thanks very much for your help! >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 14:10 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Hi Jeff, >>> >>> I have put the code online with a sample of the data here: >>> >>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>> >>> I hope you'll be able to give me some advice as it is quite difficult for >>> someone new in python and scientific computation >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> >> Antoine: I may have the size of the pixels wrong, and lat/lon >> transposed, but this is the general idea: >> >> from mpl_toolkits.basemap import Basemap >> import matplotlib.pyplot as plt >> import numpy as np >> lats = []; lons = []; data = [] >> for line in open('pixels.dat'): >> linesplit = line.split(',') >> lons.append(float(linesplit[1])) >> lats.append(float(linesplit[0])) >> data.append(float(linesplit[2])) >> map = >> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >> >> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >> x,y = map(lons,lats) >> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >> plt.colorbar(shrink=0.6) >> map.drawcoastlines() >> plt.show() >> >> -Jeff >> >> >> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:Jef...@no...] >>> Sent: mercredi 10 septembre 2008 16:45 >>> To: Antoine De Pauw >>> Cc: Matplotlib Users >>> Subject: Re: Information request >>> >>> Antoine De Pauw wrote: >>> >>> >>> >>>> Thanks Jeff, >>>> >>>> In fact my points are arranged in three unsorted arrays, with a simple >>>> >>>> >>>> >>> scheme (thats why I couldn't plot them with imshow and others) >>> >>> >>> >>>> arrays: >>>> >>>> [lat][lon][val] >>>> [-10][ 17][0.3] >>>> [ 37][ 23][3.7] >>>> ... ... ... >>>> >>>> and so for many rows... >>>> >>>> what I have to do is looping through my arrays like that >>>> >>>> while i < rowcount: >>>> plot_to_map(lat[i],lon[i],val[i]) >>>> >>>> it is evidently an idea of how it could be done easily but my knowledge >>>> >>>> >> of >> >> >>>> >>>> >>>> >>> these libraries is too weak for me to figure out how to do it >>> >>> >>> >>>> my data comes from huge binary files but is extremely simple, so it >>>> > would > >>>> >>>> >>>> >>> be really easy for anyone to help me as the problem itself is how to put >>> unsorted points on the map with latitude and longitude coordinates >>> >>> >>> Antoine: You haven't said if your data forms a rectangular array. If >>> so, you can build a 2-d array from the input file and plot it with >>> imshow. If not, you can still plug the elements into a 2-d masked >>> array, leaving the missing pixels masked. You say the points are >>> 'unsorted', does that mean they are randomly distributed and do not form >>> a rectangular grid? >>> >>> It would really be much easier to help if you gave us more information, >>> such as how the data is structured, what the pixel footprint is, etc. >>> Perhaps you could post the binary file on an ftp site somewhere with >>> code to read it. >>> >>> Also, please hit 'reply all' when replying, so the matplotlib users >>> mailing list is CC'ed. >>> >>> -Jeff >>> >>> >>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>> >>>>>> Sir, >>>>>> >>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>> >>>>>> >>>>>> >>> difficult to be understandable. >>> >>> >>> >>>>>> All is in the script I gave to you initially, except the point drawing >>>>>> >>>>>> >>>>>> >>> code which would be useless as it is proven not to work (I dont know the >>> method to do it). >>> >>> >>> >>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>> >>>>>> >>>>>> >>> geographic coordinates. >>> >>> >>> >>>>>> I cannot find the right method to put colour pixels on the map, that's >>>>>> >>>>>> >>>>>> >>> the problem. >>> >>> >>> >>>>>> I have that map in miller projection, and three arrays containing >>>>>> >>>>>> >>>>>> >>> respectively latitude, longitude and satellite measured value. >>> >>> >>> >>>>>> What I need to obtain is something approximately like this: >>>>>> >>>>>> >>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> _00_lr.gif but with the basemap toolkit. >>> >>> >>> >>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>> >>>>>> >>>>>> >>> coordinates lat:lon on that map? If I have just the method to project a >>> geographic coordinate on the map and put a coloured pixel at the right >>> place, all is done and I just have to loop my arrays... Also, I would >>> > have > >>> to implement some antialiasing on the map. >>> >>> >>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> Antoine: >>>>> >>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>> > imshow). > >>>>> >>>>> >> >> >>>>> If you could send me your data I may be able to get you started. >>>>> >>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>> >>>>> >>>>> -Jeff >>>>> >>>>> >>>>> >>>>>> If this is not possible to do it in a simple and explainable way, >>>>>> >>>>>> >> please >> >> >>>>>> >>>>>> >>>>>> >>> tell me and I'll continue using matlab or searching for the bit of code >>> which will save me >>> >>> >>> >>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>> >>>>>> Many thanks, >>>>>> >>>>>> Antoine De Pauw >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Antoine De Pauw wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Hi, and thanks for the answer >>>>>>>> >>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>> >>>>>>>> >>>>>>>> >>> (Lat,Lon,Val) describing geographic points which are associated by index >>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>> >>> >>> >>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>> >>>>>>>> >> projection >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> for most) based on latitude and longitude, to obtain a colour map (points >>> are unordered, it is from IASI satellite computations) >>> >>> >>> >>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>> >>>>>>>> >>>>>>>> >>> problem I have is any method I try for plotting points is failing, either >>> pcolor, pcolormesh, imshow, etc. >>> >>> >>> >>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>> >>>>>>>> >>>>>>>> >>> might have the experience and skills to easily explain to me how to >>> manipulate these points and plot them on the map, as there's like no help >>> >>> >> on >> >> >>> the web except standard examples... >>> >>> >>> >>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>> >>>>>>>> >> if >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> it takes too much of your time just advice me some lectures >>> >>> >>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> De Pauw Antoine >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>> > a > >>>>>>> >>>>>>> >> >> >>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> De Pauw Antoine wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Dear sir, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>> >>>>>>>>>> >> the >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> “Quantum >>> >>> >>> >>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>> >>>>>>>>>> >> de >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> any >>> >>> >>> >>>>>>>>>> points on maps. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> way, >>> >>> >>> >>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>> >>>>>>>>>> >> latitude, >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> longitude and values to plot? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>> > so > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> far >>> >>> >>> >>>>>>>>>> give me some errors… >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Thank you very much in advance, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Best regards, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> plotting part >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>> >>>>>>>>>> from numpy import * >>>>>>>>>> >>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>> >>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>> >>>>>>>>>> import numpy as np >>>>>>>>>> >>>>>>>>>> import os >>>>>>>>>> >>>>>>>>>> import sys >>>>>>>>>> >>>>>>>>>> import array >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('preparing map') >>>>>>>>>> >>>>>>>>>> map = >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>> >>>>>>>>>> map.drawmapboundary() >>>>>>>>>> >>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> print('reading binary data') >>>>>>>>>> >>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>> >>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>> >>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>> >>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>> >>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>> >>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>> >>>>>>>>>> i=0 >>>>>>>>>> >>>>>>>>>> while i < nbreligne: >>>>>>>>>> >>>>>>>>>> if(Lon[i]>180): >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> Lon[i]-=360 >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> i+=1 >>>>>>>>>> >>>>>>>>>> print('plotting data') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> #plotting code comes here >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> very >>> >>> >>> >>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>> >>>>>>>>> >> could >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> be >>> >>> >>> >>>>>>>>> your data. >>>>>>>>> >>>>>>>>> -Jeff >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('saving map') >>>>>>>>>> >>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>> >>>>>>>>>> print('done') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> *Antoine De Pauw* >>>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> IT >>> >>> >>> >>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>> >>>>>>>>>> >> chemistry >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> and >>> >>> >>> >>>>>>>>>> photophysics laboratory >>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> -- >>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
Jeff, The map object is from the Basemap type, the only different thing is the Lon,Lat and Val objects which are from the type array instead of lists Anyway, solutions are slowly showing themselves and I thank you all Have a nice day Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: jeudi 11 septembre 2008 15:29 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Thanks Jeff, > > This seems to work with csv file types, and I've been experimenting a bit > with it > > However, when I try to implement this with my original code (with binary > files), I get an error like that one: > > Traceback (most recent call last): > File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> > x,y = map(Lon,Lat) > TypeError: 'numpy.ndarray' object is not callable > > I think this is coming from the fact I use array objects to store values... > could you confirm it? > Antoine: It looks like you the object map is not a Basemap instance, but a numpy array. Try putting 'print type(map)' just ahead of this statement to verify this. I suspect your re-using the name 'map' in your code, overwriting the Basemap class instance. -Jeff > Also, I'll see if it is possible to invert color scale and mask everything > under a certain value > > Thanks very much for your help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 14:10 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I have put the code online with a sample of the data here: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> I hope you'll be able to give me some advice as it is quite difficult for >> someone new in python and scientific computation >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: I may have the size of the pixels wrong, and lat/lon > transposed, but this is the general idea: > > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > import numpy as np > lats = []; lons = []; data = [] > for line in open('pixels.dat'): > linesplit = line.split(',') > lons.append(float(linesplit[1])) > lats.append(float(linesplit[0])) > data.append(float(linesplit[2])) > map = > Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ > > urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') > x,y = map(lons,lats) > plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) > plt.colorbar(shrink=0.6) > map.drawcoastlines() > plt.show() > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:Jef...@no...] >> Sent: mercredi 10 septembre 2008 16:45 >> To: Antoine De Pauw >> Cc: Matplotlib Users >> Subject: Re: Information request >> >> Antoine De Pauw wrote: >> >> >>> Thanks Jeff, >>> >>> In fact my points are arranged in three unsorted arrays, with a simple >>> >>> >> scheme (thats why I couldn't plot them with imshow and others) >> >> >>> arrays: >>> >>> [lat][lon][val] >>> [-10][ 17][0.3] >>> [ 37][ 23][3.7] >>> ... ... ... >>> >>> and so for many rows... >>> >>> what I have to do is looping through my arrays like that >>> >>> while i < rowcount: >>> plot_to_map(lat[i],lon[i],val[i]) >>> >>> it is evidently an idea of how it could be done easily but my knowledge >>> > of > >>> >>> >> these libraries is too weak for me to figure out how to do it >> >> >>> my data comes from huge binary files but is extremely simple, so it would >>> >>> >> be really easy for anyone to help me as the problem itself is how to put >> unsorted points on the map with latitude and longitude coordinates >> >> >> Antoine: You haven't said if your data forms a rectangular array. If >> so, you can build a 2-d array from the input file and plot it with >> imshow. If not, you can still plug the elements into a 2-d masked >> array, leaving the missing pixels masked. You say the points are >> 'unsorted', does that mean they are randomly distributed and do not form >> a rectangular grid? >> >> It would really be much easier to help if you gave us more information, >> such as how the data is structured, what the pixel footprint is, etc. >> Perhaps you could post the binary file on an ftp site somewhere with >> code to read it. >> >> Also, please hit 'reply all' when replying, so the matplotlib users >> mailing list is CC'ed. >> >> -Jeff >> >> >>>> Antoine De Pauw wrote: >>>> >>>> >>>>> Sir, >>>>> >>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>> >>>>> >> difficult to be understandable. >> >> >>>>> All is in the script I gave to you initially, except the point drawing >>>>> >>>>> >> code which would be useless as it is proven not to work (I dont know the >> method to do it). >> >> >>>>> What I have is a map, and a set of pixels I have to put on it with >>>>> >>>>> >> geographic coordinates. >> >> >>>>> I cannot find the right method to put colour pixels on the map, that's >>>>> >>>>> >> the problem. >> >> >>>>> I have that map in miller projection, and three arrays containing >>>>> >>>>> >> respectively latitude, longitude and satellite measured value. >> >> >>>>> What I need to obtain is something approximately like this: >>>>> >>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> _00_lr.gif but with the basemap toolkit. >> >> >>>>> So, my question is: how could I do to plot a coloured pixel at >>>>> >>>>> >> coordinates lat:lon on that map? If I have just the method to project a >> geographic coordinate on the map and put a coloured pixel at the right >> place, all is done and I just have to loop my arrays... Also, I would have >> to implement some antialiasing on the map. >> >> >>>>> >>>>> >>>>> >>>> Antoine: >>>> >>>> Are the pixels arranged on a regular grid - or are they randomly >>>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>>> > > >>>> If you could send me your data I may be able to get you started. >>>> >>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>> >>>> >>>> -Jeff >>>> >>>> >>>>> If this is not possible to do it in a simple and explainable way, >>>>> > please > >>>>> >>>>> >> tell me and I'll continue using matlab or searching for the bit of code >> which will save me >> >> >>>>> Anyway, I have to thank you for your interest to help me.. >>>>> >>>>> Many thanks, >>>>> >>>>> Antoine De Pauw >>>>> >>>>> >>>>> >>>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>>> Hi, and thanks for the answer >>>>>>> >>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>> >>>>>>> >> (Lat,Lon,Val) describing geographic points which are associated by index >> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >> >> >>>>>>> What I need to do is to plot some points on the map (miller >>>>>>> > projection > >>>>>>> >>>>>>> >> for most) based on latitude and longitude, to obtain a colour map (points >> are unordered, it is from IASI satellite computations) >> >> >>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>> >>>>>>> >> problem I have is any method I try for plotting points is failing, either >> pcolor, pcolormesh, imshow, etc. >> >> >>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>> >>>>>>> >> might have the experience and skills to easily explain to me how to >> manipulate these points and plot them on the map, as there's like no help >> > on > >> the web except standard examples... >> >> >>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>> > if > >>>>>>> >>>>>>> >> it takes too much of your time just advice me some lectures >> >> >>>>>>> Best regards, >>>>>>> >>>>>>> De Pauw Antoine >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: It would really help to have a script demonstrating your >>>>>> problem. It sounds to me like you want to plot markers representing a >>>>>> > > >>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>> pcolormesh and friends are for plotting gridded data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> De Pauw Antoine wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Dear sir, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>> > the > >>>>>>>>> >>>>>>>>> >> “Quantum >> >> >>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>> > de > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>> solution, on an explanation from you here: >>>>>>>>> >>>>>>>>> >>>>>>>>> >> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>> >>>>>>>>> >> any >> >> >>>>>>>>> points on maps. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>> >>>>>>>>> >> way, >> >> >>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>> > latitude, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> longitude and values to plot? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>>> >>>>>>>>> >> far >> >> >>>>>>>>> give me some errors… >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Thank you very much in advance, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>> >>>>>>>>> >> plotting part >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>> >>>>>>>>> from numpy import * >>>>>>>>> >>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>> >>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>> >>>>>>>>> import numpy as np >>>>>>>>> >>>>>>>>> import os >>>>>>>>> >>>>>>>>> import sys >>>>>>>>> >>>>>>>>> import array >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('preparing map') >>>>>>>>> >>>>>>>>> map = >>>>>>>>> >>>>>>>>> >>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>> >>>>>>>>> map.drawmapboundary() >>>>>>>>> >>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>> >>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>> >>>>>>>>> print('reading binary data') >>>>>>>>> >>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>> >>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Val=zeros(nbreligne) >>>>>>>>> >>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>> >>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>> >>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>> >>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>> >>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>> >>>>>>>>> i=0 >>>>>>>>> >>>>>>>>> while i < nbreligne: >>>>>>>>> >>>>>>>>> if(Lon[i]>180): >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> Lon[i]-=360 >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> i+=1 >>>>>>>>> >>>>>>>>> print('plotting data') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> #plotting code comes here >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>> >>>>>>>> >> very >> >> >>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>> > could > >>>>>>>> >>>>>>>> >> be >> >> >>>>>>>> your data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('saving map') >>>>>>>>> >>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>> >>>>>>>>> print('done') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> *Antoine De Pauw* >>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>> >>>>>>>>> >> IT >> >> >>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>> > chemistry > >>>>>>>>> >>>>>>>>> >> and >> >> >>>>>>>>> photophysics laboratory >>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
De Pauw Antoine wrote: > Thanks Jeff, > > This seems to work with csv file types, and I've been experimenting a bit > with it > > However, when I try to implement this with my original code (with binary > files), I get an error like that one: > > Traceback (most recent call last): > File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> > x,y = map(Lon,Lat) > TypeError: 'numpy.ndarray' object is not callable > > I think this is coming from the fact I use array objects to store values... > could you confirm it? > Antoine: It looks like you the object map is not a Basemap instance, but a numpy array. Try putting 'print type(map)' just ahead of this statement to verify this. I suspect your re-using the name 'map' in your code, overwriting the Basemap class instance. -Jeff > Also, I'll see if it is possible to invert color scale and mask everything > under a certain value > > Thanks very much for your help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 14:10 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I have put the code online with a sample of the data here: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> I hope you'll be able to give me some advice as it is quite difficult for >> someone new in python and scientific computation >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: I may have the size of the pixels wrong, and lat/lon > transposed, but this is the general idea: > > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > import numpy as np > lats = []; lons = []; data = [] > for line in open('pixels.dat'): > linesplit = line.split(',') > lons.append(float(linesplit[1])) > lats.append(float(linesplit[0])) > data.append(float(linesplit[2])) > map = > Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ > > urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') > x,y = map(lons,lats) > plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) > plt.colorbar(shrink=0.6) > map.drawcoastlines() > plt.show() > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:Jef...@no...] >> Sent: mercredi 10 septembre 2008 16:45 >> To: Antoine De Pauw >> Cc: Matplotlib Users >> Subject: Re: Information request >> >> Antoine De Pauw wrote: >> >> >>> Thanks Jeff, >>> >>> In fact my points are arranged in three unsorted arrays, with a simple >>> >>> >> scheme (thats why I couldn't plot them with imshow and others) >> >> >>> arrays: >>> >>> [lat][lon][val] >>> [-10][ 17][0.3] >>> [ 37][ 23][3.7] >>> ... ... ... >>> >>> and so for many rows... >>> >>> what I have to do is looping through my arrays like that >>> >>> while i < rowcount: >>> plot_to_map(lat[i],lon[i],val[i]) >>> >>> it is evidently an idea of how it could be done easily but my knowledge >>> > of > >>> >>> >> these libraries is too weak for me to figure out how to do it >> >> >>> my data comes from huge binary files but is extremely simple, so it would >>> >>> >> be really easy for anyone to help me as the problem itself is how to put >> unsorted points on the map with latitude and longitude coordinates >> >> >> Antoine: You haven't said if your data forms a rectangular array. If >> so, you can build a 2-d array from the input file and plot it with >> imshow. If not, you can still plug the elements into a 2-d masked >> array, leaving the missing pixels masked. You say the points are >> 'unsorted', does that mean they are randomly distributed and do not form >> a rectangular grid? >> >> It would really be much easier to help if you gave us more information, >> such as how the data is structured, what the pixel footprint is, etc. >> Perhaps you could post the binary file on an ftp site somewhere with >> code to read it. >> >> Also, please hit 'reply all' when replying, so the matplotlib users >> mailing list is CC'ed. >> >> -Jeff >> >> >>>> Antoine De Pauw wrote: >>>> >>>> >>>>> Sir, >>>>> >>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>> >>>>> >> difficult to be understandable. >> >> >>>>> All is in the script I gave to you initially, except the point drawing >>>>> >>>>> >> code which would be useless as it is proven not to work (I dont know the >> method to do it). >> >> >>>>> What I have is a map, and a set of pixels I have to put on it with >>>>> >>>>> >> geographic coordinates. >> >> >>>>> I cannot find the right method to put colour pixels on the map, that's >>>>> >>>>> >> the problem. >> >> >>>>> I have that map in miller projection, and three arrays containing >>>>> >>>>> >> respectively latitude, longitude and satellite measured value. >> >> >>>>> What I need to obtain is something approximately like this: >>>>> >>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> _00_lr.gif but with the basemap toolkit. >> >> >>>>> So, my question is: how could I do to plot a coloured pixel at >>>>> >>>>> >> coordinates lat:lon on that map? If I have just the method to project a >> geographic coordinate on the map and put a coloured pixel at the right >> place, all is done and I just have to loop my arrays... Also, I would have >> to implement some antialiasing on the map. >> >> >>>>> >>>>> >>>>> >>>> Antoine: >>>> >>>> Are the pixels arranged on a regular grid - or are they randomly >>>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>>> > > >>>> If you could send me your data I may be able to get you started. >>>> >>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>> >>>> >>>> -Jeff >>>> >>>> >>>>> If this is not possible to do it in a simple and explainable way, >>>>> > please > >>>>> >>>>> >> tell me and I'll continue using matlab or searching for the bit of code >> which will save me >> >> >>>>> Anyway, I have to thank you for your interest to help me.. >>>>> >>>>> Many thanks, >>>>> >>>>> Antoine De Pauw >>>>> >>>>> >>>>> >>>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>>> Hi, and thanks for the answer >>>>>>> >>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>> >>>>>>> >> (Lat,Lon,Val) describing geographic points which are associated by index >> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >> >> >>>>>>> What I need to do is to plot some points on the map (miller >>>>>>> > projection > >>>>>>> >>>>>>> >> for most) based on latitude and longitude, to obtain a colour map (points >> are unordered, it is from IASI satellite computations) >> >> >>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>> >>>>>>> >> problem I have is any method I try for plotting points is failing, either >> pcolor, pcolormesh, imshow, etc. >> >> >>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>> >>>>>>> >> might have the experience and skills to easily explain to me how to >> manipulate these points and plot them on the map, as there's like no help >> > on > >> the web except standard examples... >> >> >>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>> > if > >>>>>>> >>>>>>> >> it takes too much of your time just advice me some lectures >> >> >>>>>>> Best regards, >>>>>>> >>>>>>> De Pauw Antoine >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: It would really help to have a script demonstrating your >>>>>> problem. It sounds to me like you want to plot markers representing a >>>>>> > > >>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>> pcolormesh and friends are for plotting gridded data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> De Pauw Antoine wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Dear sir, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>> > the > >>>>>>>>> >>>>>>>>> >> “Quantum >> >> >>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>> > de > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>> solution, on an explanation from you here: >>>>>>>>> >>>>>>>>> >>>>>>>>> >> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>> >>>>>>>>> >> any >> >> >>>>>>>>> points on maps. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>> >>>>>>>>> >> way, >> >> >>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>> > latitude, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> longitude and values to plot? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>>> >>>>>>>>> >> far >> >> >>>>>>>>> give me some errors… >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Thank you very much in advance, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>> >>>>>>>>> >> plotting part >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>> >>>>>>>>> from numpy import * >>>>>>>>> >>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>> >>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>> >>>>>>>>> import numpy as np >>>>>>>>> >>>>>>>>> import os >>>>>>>>> >>>>>>>>> import sys >>>>>>>>> >>>>>>>>> import array >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('preparing map') >>>>>>>>> >>>>>>>>> map = >>>>>>>>> >>>>>>>>> >>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>> >>>>>>>>> map.drawmapboundary() >>>>>>>>> >>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>> >>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>> >>>>>>>>> print('reading binary data') >>>>>>>>> >>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>> >>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Val=zeros(nbreligne) >>>>>>>>> >>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>> >>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>> >>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>> >>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>> >>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>> >>>>>>>>> i=0 >>>>>>>>> >>>>>>>>> while i < nbreligne: >>>>>>>>> >>>>>>>>> if(Lon[i]>180): >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> Lon[i]-=360 >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> i+=1 >>>>>>>>> >>>>>>>>> print('plotting data') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> #plotting code comes here >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>> >>>>>>>> >> very >> >> >>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>> > could > >>>>>>>> >>>>>>>> >> be >> >> >>>>>>>> your data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('saving map') >>>>>>>>> >>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>> >>>>>>>>> print('done') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> *Antoine De Pauw* >>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>> >>>>>>>>> >> IT >> >> >>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>> > chemistry > >>>>>>>>> >>>>>>>>> >> and >> >> >>>>>>>>> photophysics laboratory >>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
Thanks Jeff, This seems to work with csv file types, and I've been experimenting a bit with it However, when I try to implement this with my original code (with binary files), I get an error like that one: Traceback (most recent call last): File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> x,y = map(Lon,Lat) TypeError: 'numpy.ndarray' object is not callable I think this is coming from the fact I use array objects to store values... could you confirm it? Also, I'll see if it is possible to invert color scale and mask everything under a certain value Thanks very much for your help! Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: jeudi 11 septembre 2008 14:10 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi Jeff, > > I have put the code online with a sample of the data here: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > I hope you'll be able to give me some advice as it is quite difficult for > someone new in python and scientific computation > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: I may have the size of the pixels wrong, and lat/lon transposed, but this is the general idea: from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np lats = []; lons = []; data = [] for line in open('pixels.dat'): linesplit = line.split(',') lons.append(float(linesplit[1])) lats.append(float(linesplit[0])) data.append(float(linesplit[2])) map = Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') x,y = map(lons,lats) plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) plt.colorbar(shrink=0.6) map.drawcoastlines() plt.show() -Jeff > -----Original Message----- > From: Jeff Whitaker [mailto:Jef...@no...] > Sent: mercredi 10 septembre 2008 16:45 > To: Antoine De Pauw > Cc: Matplotlib Users > Subject: Re: Information request > > Antoine De Pauw wrote: > >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple >> > scheme (thats why I couldn't plot them with imshow and others) > >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of >> > these libraries is too weak for me to figure out how to do it > >> my data comes from huge binary files but is extremely simple, so it would >> > be really easy for anyone to help me as the problem itself is how to put > unsorted points on the map with latitude and longitude coordinates > > > Antoine: You haven't said if your data forms a rectangular array. If > so, you can build a 2-d array from the input file and plot it with > imshow. If not, you can still plug the elements into a 2-d masked > array, leaving the missing pixels masked. You say the points are > 'unsorted', does that mean they are randomly distributed and do not form > a rectangular grid? > > It would really be much easier to help if you gave us more information, > such as how the data is structured, what the pixel footprint is, etc. > Perhaps you could post the binary file on an ftp site somewhere with > code to read it. > > Also, please hit 'reply all' when replying, so the matplotlib users > mailing list is CC'ed. > > -Jeff > >>> Antoine De Pauw wrote: >>> >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>> > difficult to be understandable. > >>>> All is in the script I gave to you initially, except the point drawing >>>> > code which would be useless as it is proven not to work (I dont know the > method to do it). > >>>> What I have is a map, and a set of pixels I have to put on it with >>>> > geographic coordinates. > >>>> I cannot find the right method to put colour pixels on the map, that's >>>> > the problem. > >>>> I have that map in miller projection, and three arrays containing >>>> > respectively latitude, longitude and satellite measured value. > >>>> What I need to obtain is something approximately like this: >>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > _00_lr.gif but with the basemap toolkit. > >>>> So, my question is: how could I do to plot a coloured pixel at >>>> > coordinates lat:lon on that map? If I have just the method to project a > geographic coordinate on the map and put a coloured pixel at the right > place, all is done and I just have to loop my arrays... Also, I would have > to implement some antialiasing on the map. > >>>> >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>> >>>> If this is not possible to do it in a simple and explainable way, please >>>> > tell me and I'll continue using matlab or searching for the bit of code > which will save me > >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>> > (Lat,Lon,Val) describing geographic points which are associated by index > (like point 1 is Lat[0]:Lon[0] with value Val[0]) > >>>>>> What I need to do is to plot some points on the map (miller projection >>>>>> > for most) based on latitude and longitude, to obtain a colour map (points > are unordered, it is from IASI satellite computations) > >>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>> > problem I have is any method I try for plotting points is failing, either > pcolor, pcolormesh, imshow, etc. > >>>>>> When I found your post on that mailing list, I figured out that you >>>>>> > might have the experience and skills to easily explain to me how to > manipulate these points and plot them on the map, as there's like no help on > the web except standard examples... > >>>>>> Please tell me if this is possible for you to give me some tips, or if >>>>>> > it takes too much of your time just advice me some lectures > >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the >>>>>>>> > “Quantum > >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> > > >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> >>>>>>>> > http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html > >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>> > any > >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>> > way, > >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> > > >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>> > far > >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>> > plotting part > >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> >>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>> > very > >>>>>>> little to work with - it could be your plotting commands, or it could >>>>>>> > be > >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>> > IT > >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>>>>> > and > >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >>> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
De Pauw Antoine wrote: > Hi Jeff, > > I have put the code online with a sample of the data here: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > I hope you'll be able to give me some advice as it is quite difficult for > someone new in python and scientific computation > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: I may have the size of the pixels wrong, and lat/lon transposed, but this is the general idea: from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np lats = []; lons = []; data = [] for line in open('pixels.dat'): linesplit = line.split(',') lons.append(float(linesplit[1])) lats.append(float(linesplit[0])) data.append(float(linesplit[2])) map = Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') x,y = map(lons,lats) plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) plt.colorbar(shrink=0.6) map.drawcoastlines() plt.show() -Jeff > -----Original Message----- > From: Jeff Whitaker [mailto:Jef...@no...] > Sent: mercredi 10 septembre 2008 16:45 > To: Antoine De Pauw > Cc: Matplotlib Users > Subject: Re: Information request > > Antoine De Pauw wrote: > >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple >> > scheme (thats why I couldn't plot them with imshow and others) > >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of >> > these libraries is too weak for me to figure out how to do it > >> my data comes from huge binary files but is extremely simple, so it would >> > be really easy for anyone to help me as the problem itself is how to put > unsorted points on the map with latitude and longitude coordinates > > > Antoine: You haven't said if your data forms a rectangular array. If > so, you can build a 2-d array from the input file and plot it with > imshow. If not, you can still plug the elements into a 2-d masked > array, leaving the missing pixels masked. You say the points are > 'unsorted', does that mean they are randomly distributed and do not form > a rectangular grid? > > It would really be much easier to help if you gave us more information, > such as how the data is structured, what the pixel footprint is, etc. > Perhaps you could post the binary file on an ftp site somewhere with > code to read it. > > Also, please hit 'reply all' when replying, so the matplotlib users > mailing list is CC'ed. > > -Jeff > >>> Antoine De Pauw wrote: >>> >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>> > difficult to be understandable. > >>>> All is in the script I gave to you initially, except the point drawing >>>> > code which would be useless as it is proven not to work (I dont know the > method to do it). > >>>> What I have is a map, and a set of pixels I have to put on it with >>>> > geographic coordinates. > >>>> I cannot find the right method to put colour pixels on the map, that's >>>> > the problem. > >>>> I have that map in miller projection, and three arrays containing >>>> > respectively latitude, longitude and satellite measured value. > >>>> What I need to obtain is something approximately like this: >>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > _00_lr.gif but with the basemap toolkit. > >>>> So, my question is: how could I do to plot a coloured pixel at >>>> > coordinates lat:lon on that map? If I have just the method to project a > geographic coordinate on the map and put a coloured pixel at the right > place, all is done and I just have to loop my arrays... Also, I would have > to implement some antialiasing on the map. > >>>> >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>> >>>> If this is not possible to do it in a simple and explainable way, please >>>> > tell me and I'll continue using matlab or searching for the bit of code > which will save me > >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>> > (Lat,Lon,Val) describing geographic points which are associated by index > (like point 1 is Lat[0]:Lon[0] with value Val[0]) > >>>>>> What I need to do is to plot some points on the map (miller projection >>>>>> > for most) based on latitude and longitude, to obtain a colour map (points > are unordered, it is from IASI satellite computations) > >>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>> > problem I have is any method I try for plotting points is failing, either > pcolor, pcolormesh, imshow, etc. > >>>>>> When I found your post on that mailing list, I figured out that you >>>>>> > might have the experience and skills to easily explain to me how to > manipulate these points and plot them on the map, as there's like no help on > the web except standard examples... > >>>>>> Please tell me if this is possible for you to give me some tips, or if >>>>>> > it takes too much of your time just advice me some lectures > >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the >>>>>>>> > “Quantum > >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> > > >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> >>>>>>>> > http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html > >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>> > any > >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>> > way, > >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> > > >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>> > far > >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>> > plotting part > >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> >>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>> > very > >>>>>>> little to work with - it could be your plotting commands, or it could >>>>>>> > be > >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>> > IT > >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>>>>> > and > >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >>> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
De Pauw Antoine wrote: > Hi Jeff, > > I have put the code online with a sample of the data here: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > I hope you'll be able to give me some advice as it is quite difficult for > someone new in python and scientific computation > Antoine: How big are the pixels? Is the text file lon,lat,data or lat,lon,data? -Jeff > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > -----Original Message----- > From: Jeff Whitaker [mailto:Jef...@no...] > Sent: mercredi 10 septembre 2008 16:45 > To: Antoine De Pauw > Cc: Matplotlib Users > Subject: Re: Information request > > Antoine De Pauw wrote: > >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple >> > scheme (thats why I couldn't plot them with imshow and others) > >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of >> > these libraries is too weak for me to figure out how to do it > >> my data comes from huge binary files but is extremely simple, so it would >> > be really easy for anyone to help me as the problem itself is how to put > unsorted points on the map with latitude and longitude coordinates > > > Antoine: You haven't said if your data forms a rectangular array. If > so, you can build a 2-d array from the input file and plot it with > imshow. If not, you can still plug the elements into a 2-d masked > array, leaving the missing pixels masked. You say the points are > 'unsorted', does that mean they are randomly distributed and do not form > a rectangular grid? > > It would really be much easier to help if you gave us more information, > such as how the data is structured, what the pixel footprint is, etc. > Perhaps you could post the binary file on an ftp site somewhere with > code to read it. > > Also, please hit 'reply all' when replying, so the matplotlib users > mailing list is CC'ed. > > -Jeff > >>> Antoine De Pauw wrote: >>> >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>> > difficult to be understandable. > >>>> All is in the script I gave to you initially, except the point drawing >>>> > code which would be useless as it is proven not to work (I dont know the > method to do it). > >>>> What I have is a map, and a set of pixels I have to put on it with >>>> > geographic coordinates. > >>>> I cannot find the right method to put colour pixels on the map, that's >>>> > the problem. > >>>> I have that map in miller projection, and three arrays containing >>>> > respectively latitude, longitude and satellite measured value. > >>>> What I need to obtain is something approximately like this: >>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > _00_lr.gif but with the basemap toolkit. > >>>> So, my question is: how could I do to plot a coloured pixel at >>>> > coordinates lat:lon on that map? If I have just the method to project a > geographic coordinate on the map and put a coloured pixel at the right > place, all is done and I just have to loop my arrays... Also, I would have > to implement some antialiasing on the map. > >>>> >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>> >>>> If this is not possible to do it in a simple and explainable way, please >>>> > tell me and I'll continue using matlab or searching for the bit of code > which will save me > >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>> > (Lat,Lon,Val) describing geographic points which are associated by index > (like point 1 is Lat[0]:Lon[0] with value Val[0]) > >>>>>> What I need to do is to plot some points on the map (miller projection >>>>>> > for most) based on latitude and longitude, to obtain a colour map (points > are unordered, it is from IASI satellite computations) > >>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>> > problem I have is any method I try for plotting points is failing, either > pcolor, pcolormesh, imshow, etc. > >>>>>> When I found your post on that mailing list, I figured out that you >>>>>> > might have the experience and skills to easily explain to me how to > manipulate these points and plot them on the map, as there's like no help on > the web except standard examples... > >>>>>> Please tell me if this is possible for you to give me some tips, or if >>>>>> > it takes too much of your time just advice me some lectures > >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the >>>>>>>> > “Quantum > >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> > > >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> >>>>>>>> > http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html > >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>> > any > >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>> > way, > >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> > > >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>> > far > >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>> > plotting part > >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> >>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>> > very > >>>>>>> little to work with - it could be your plotting commands, or it could >>>>>>> > be > >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>> > IT > >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>>>>> > and > >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >>> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
Hi all, with few free hours, I have modified the windrose file to be O.O. compliant with the 0.98 matplotlib branch and normally bug free. The next posts will be on sourceforge : https://sourceforge.net/project/showfiles.php?group_id=239240&package_id=290902 and to see it in detail, here is the entry on blogspot: http://youarealegend.blogspot.com/2008/09/windrose.html All suggestion welcome (even to correct my bad english ;-) ) Thanks to the best python plotting library and the matplotlib team! -- Lionel Roubeyrie
Hi Jeff, I have put the code online with a sample of the data here: http://snipplr.com/view/8307/map-plotting-python-code-temporary/ I hope you'll be able to give me some advice as it is quite difficult for someone new in python and scientific computation Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:Jef...@no...] Sent: mercredi 10 septembre 2008 16:45 To: Antoine De Pauw Cc: Matplotlib Users Subject: Re: Information request Antoine De Pauw wrote: > Thanks Jeff, > > In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) > > arrays: > > [lat][lon][val] > [-10][ 17][0.3] > [ 37][ 23][3.7] > ... ... ... > > and so for many rows... > > what I have to do is looping through my arrays like that > > while i < rowcount: > plot_to_map(lat[i],lon[i],val[i]) > > it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it > > my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates > Antoine: You haven't said if your data forms a rectangular array. If so, you can build a 2-d array from the input file and plot it with imshow. If not, you can still plug the elements into a 2-d masked array, leaving the missing pixels masked. You say the points are 'unsorted', does that mean they are randomly distributed and do not form a rectangular grid? It would really be much easier to help if you gave us more information, such as how the data is structured, what the pixel footprint is, etc. Perhaps you could post the binary file on an ftp site somewhere with code to read it. Also, please hit 'reply all' when replying, so the matplotlib users mailing list is CC'ed. -Jeff >> Antoine De Pauw wrote: >>> Sir, >>> >>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>> >>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>> >>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>> >>> I cannot find the right method to put colour pixels on the map, that's the problem. >>> >>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>> >>> What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 _00_lr.gif but with the basemap toolkit. >>> >>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>> >> Antoine: >> >> Are the pixels arranged on a regular grid - or are they randomly >> distributed? If they are on a grid, it's easy (using pcolor or imshow). >> >> If you could send me your data I may be able to get you started. >> >> (I'm cc'ing the matplotlib list so others can join in the discussion). >> >> >> -Jeff >>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>> >>> Anyway, I have to thank you for your interest to help me.. >>> >>> Many thanks, >>> >>> Antoine De Pauw >>> >>> >>>> Antoine De Pauw wrote: >>>> >>>>> Hi, and thanks for the answer >>>>> >>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>> >>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>> >>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>> >>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>> >>>>> Best regards, >>>>> >>>>> De Pauw Antoine >>>>> >>>>> >>>> Antoine: It would really help to have a script demonstrating your >>>> problem. It sounds to me like you want to plot markers representing a >>>> set of points - for that you should use the scatter method. pcolor, >>>> pcolormesh and friends are for plotting gridded data. >>>> >>>> -Jeff >>>> >>>>> >>>>> >>>>>> De Pauw Antoine wrote: >>>>>> >>>>>> >>>>>>> Dear sir, >>>>>>> >>>>>>> >>>>>>> >>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>> solution, on an explanation from you here: >>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>> >>>>>>> >>>>>>> >>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>> points on maps. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>> longitude and values to plot? >>>>>>> >>>>>>> >>>>>>> >>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>> give me some errors… >>>>>>> >>>>>>> >>>>>>> >>>>>>> Thank you very much in advance, >>>>>>> >>>>>>> >>>>>>> >>>>>>> Best regards, >>>>>>> >>>>>>> >>>>>>> >>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>> >>>>>>> >>>>>>> >>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>> >>>>>>> from numpy import * >>>>>>> >>>>>>> from scipy.io.numpyio import fread >>>>>>> >>>>>>> import matplotlib.pyplot as plt >>>>>>> >>>>>>> import numpy as np >>>>>>> >>>>>>> import os >>>>>>> >>>>>>> import sys >>>>>>> >>>>>>> import array >>>>>>> >>>>>>> >>>>>>> >>>>>>> fileName="c:/20080821.b56" >>>>>>> >>>>>>> >>>>>>> >>>>>>> print('preparing map') >>>>>>> >>>>>>> map = >>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>> >>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>> >>>>>>> map.drawmapboundary() >>>>>>> >>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>> >>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>> >>>>>>> print('reading binary data') >>>>>>> >>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>> >>>>>>> Lat=zeros(nbreligne) >>>>>>> >>>>>>> Lon=zeros(nbreligne) >>>>>>> >>>>>>> Val=zeros(nbreligne) >>>>>>> >>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>> >>>>>>> Lat=rawfile[0:nbreligne] >>>>>>> >>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>> >>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>> >>>>>>> print('shifting latitudes and projecting to map') >>>>>>> >>>>>>> i=0 >>>>>>> >>>>>>> while i < nbreligne: >>>>>>> >>>>>>> if(Lon[i]>180): >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> Lon[i]-=360 >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> i+=1 >>>>>>> >>>>>>> print('plotting data') >>>>>>> >>>>>>> >>>>>>> >>>>>>> #plotting code comes here >>>>>>> >>>>>>> >>>>>> Antoine: If you send me a self-contained script that produces the >>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>> little to work with - it could be your plotting commands, or it could be >>>>>> your data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> print('saving map') >>>>>>> >>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>> >>>>>>> print('done') >>>>>>> >>>>>>> >>>>>>> >>>>>>> *Antoine De Pauw* >>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>> photophysics laboratory >>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> Meteorologist FAX : (303)497-6449 >>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>> >>> >> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
On Wed, Sep 10, 2008 at 2:55 PM, Samir Wadhawan <sam...@gm...> wrote: > Hi, > > I am trying to draw a rectangle of a fixed size and them put a lable/text on > it. However if the text is too long, it goes out of bounds. Is there a way I > restrict the text within the rectangle margins. would it suffice to draw text and put a rectangle around it? If so, you can do ax.text(x, y, label, bbox=dict(facecolor=red, alpha=0.5)) where bbox is a dict of Rectangle properties I suspect this is not what you are looking for based on your question, but I wanted to mention it just in case. JDH
Hi, I am trying to draw a rectangle of a fixed size and them put a lable/text on it. However if the text is too long, it goes out of bounds. Is there a way I restrict the text within the rectangle margins. heres what I am using ###################################### def rectangle(self, lower, upper, node1, branch_name): rect = Rectangle(lower, upper[0]-lower[0], upper[1] - lower[1], edgecolor='k', facecolor= self.color_method(node1)) self.ax.add_patch(rect) self.ax.text(lower[0] + (upper[0]-lower[0])/2, lower[1] + (upper[1]-lower[1])/2, branch_name, ha='left', va='center', fontsize='xx-small') ######################################## Any thoughts / suggestion will be really appreciated. Thanks samir
in fact the points are not in a rectangular array and pixels are missing, like you said I'll put the code and binary file online tomorrow as I have not access to it today, but reading it is not the problem when read, the values are in three arrays of same size, which I will have to convert to a 2D masked array... we'll see tomorrow if I have succeeded many thanks >Antoine De Pauw wrote: >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) >> >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it >> >> my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates >> > >Antoine: You haven't said if your data forms a rectangular array. If >so, you can build a 2-d array from the input file and plot it with >imshow. If not, you can still plug the elements into a 2-d masked >array, leaving the missing pixels masked. You say the points are >'unsorted', does that mean they are randomly distributed and do not form >a rectangular grid? > >It would really be much easier to help if you gave us more information, >such as how the data is structured, what the pixel footprint is, etc. >Perhaps you could post the binary file on an ftp site somewhere with >code to read it. > >Also, please hit 'reply all' when replying, so the matplotlib users >mailing list is CC'ed. > >-Jeff >>> Antoine De Pauw wrote: >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>>> >>>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>>> >>>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>>> >>>> I cannot find the right method to put colour pixels on the map, that's the problem. >>>> >>>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>>> >>>> What I need to obtain is something approximately like this: http://wwwoma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. >>>> >>>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow) >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>>> >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>>> >>>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>>> >>>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>>> >>>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>>> >>>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>>> >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>>> >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>>> little to work with - it could be your plotting commands, or it could be >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >> >> > > >-- >Jeffrey S. Whitaker Phone : (303)497-6313 >Meteorologist FAX : (303)497-6449 >NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >325 Broadway Office : Skaggs Research Cntr 1D-113 >Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg > >
Antoine De Pauw wrote: > Thanks Jeff, > > In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) > > arrays: > > [lat][lon][val] > [-10][ 17][0.3] > [ 37][ 23][3.7] > ... ... ... > > and so for many rows... > > what I have to do is looping through my arrays like that > > while i < rowcount: > plot_to_map(lat[i],lon[i],val[i]) > > it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it > > my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates > Antoine: You haven't said if your data forms a rectangular array. If so, you can build a 2-d array from the input file and plot it with imshow. If not, you can still plug the elements into a 2-d masked array, leaving the missing pixels masked. You say the points are 'unsorted', does that mean they are randomly distributed and do not form a rectangular grid? It would really be much easier to help if you gave us more information, such as how the data is structured, what the pixel footprint is, etc. Perhaps you could post the binary file on an ftp site somewhere with code to read it. Also, please hit 'reply all' when replying, so the matplotlib users mailing list is CC'ed. -Jeff >> Antoine De Pauw wrote: >>> Sir, >>> >>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>> >>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>> >>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>> >>> I cannot find the right method to put colour pixels on the map, that's the problem. >>> >>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>> >>> What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. >>> >>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>> >> Antoine: >> >> Are the pixels arranged on a regular grid - or are they randomly >> distributed? If they are on a grid, it's easy (using pcolor or imshow). >> >> If you could send me your data I may be able to get you started. >> >> (I'm cc'ing the matplotlib list so others can join in the discussion). >> >> >> -Jeff >>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>> >>> Anyway, I have to thank you for your interest to help me.. >>> >>> Many thanks, >>> >>> Antoine De Pauw >>> >>> >>>> Antoine De Pauw wrote: >>>> >>>>> Hi, and thanks for the answer >>>>> >>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>> >>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>> >>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>> >>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>> >>>>> Best regards, >>>>> >>>>> De Pauw Antoine >>>>> >>>>> >>>> Antoine: It would really help to have a script demonstrating your >>>> problem. It sounds to me like you want to plot markers representing a >>>> set of points - for that you should use the scatter method. pcolor, >>>> pcolormesh and friends are for plotting gridded data. >>>> >>>> -Jeff >>>> >>>>> >>>>> >>>>>> De Pauw Antoine wrote: >>>>>> >>>>>> >>>>>>> Dear sir, >>>>>>> >>>>>>> >>>>>>> >>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>> solution, on an explanation from you here: >>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>> >>>>>>> >>>>>>> >>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>> points on maps. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>> longitude and values to plot? >>>>>>> >>>>>>> >>>>>>> >>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>> give me some errors… >>>>>>> >>>>>>> >>>>>>> >>>>>>> Thank you very much in advance, >>>>>>> >>>>>>> >>>>>>> >>>>>>> Best regards, >>>>>>> >>>>>>> >>>>>>> >>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>> >>>>>>> >>>>>>> >>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>> >>>>>>> from numpy import * >>>>>>> >>>>>>> from scipy.io.numpyio import fread >>>>>>> >>>>>>> import matplotlib.pyplot as plt >>>>>>> >>>>>>> import numpy as np >>>>>>> >>>>>>> import os >>>>>>> >>>>>>> import sys >>>>>>> >>>>>>> import array >>>>>>> >>>>>>> >>>>>>> >>>>>>> fileName="c:/20080821.b56" >>>>>>> >>>>>>> >>>>>>> >>>>>>> print('preparing map') >>>>>>> >>>>>>> map = >>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>> >>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>> >>>>>>> map.drawmapboundary() >>>>>>> >>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>> >>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>> >>>>>>> print('reading binary data') >>>>>>> >>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>> >>>>>>> Lat=zeros(nbreligne) >>>>>>> >>>>>>> Lon=zeros(nbreligne) >>>>>>> >>>>>>> Val=zeros(nbreligne) >>>>>>> >>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>> >>>>>>> Lat=rawfile[0:nbreligne] >>>>>>> >>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>> >>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>> >>>>>>> print('shifting latitudes and projecting to map') >>>>>>> >>>>>>> i=0 >>>>>>> >>>>>>> while i < nbreligne: >>>>>>> >>>>>>> if(Lon[i]>180): >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> Lon[i]-=360 >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> i+=1 >>>>>>> >>>>>>> print('plotting data') >>>>>>> >>>>>>> >>>>>>> >>>>>>> #plotting code comes here >>>>>>> >>>>>>> >>>>>> Antoine: If you send me a self-contained script that produces the >>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>> little to work with - it could be your plotting commands, or it could be >>>>>> your data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> print('saving map') >>>>>>> >>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>> >>>>>>> print('done') >>>>>>> >>>>>>> >>>>>>> >>>>>>> *Antoine De Pauw* >>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>> photophysics laboratory >>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> Meteorologist FAX : (303)497-6449 >>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>> >>> >> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
Antoine De Pauw wrote: > Sir, > > I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. > > All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). > > What I have is a map, and a set of pixels I have to put on it with geographic coordinates. > > I cannot find the right method to put colour pixels on the map, that's the problem. > > I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. > > What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. > > So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. > Antoine: Are the pixels arranged on a regular grid - or are they randomly distributed? If they are on a grid, it's easy (using pcolor or imshow). If you could send me your data I may be able to get you started. (I'm cc'ing the matplotlib list so others can join in the discussion). -Jeff > If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me > > Anyway, I have to thank you for your interest to help me.. > > Many thanks, > > Antoine De Pauw > > >> Antoine De Pauw wrote: >> >>> Hi, and thanks for the answer >>> >>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>> >>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>> >>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>> >>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>> >>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>> >>> Best regards, >>> >>> De Pauw Antoine >>> >>> >> Antoine: It would really help to have a script demonstrating your >> problem. It sounds to me like you want to plot markers representing a >> set of points - for that you should use the scatter method. pcolor, >> pcolormesh and friends are for plotting gridded data. >> >> -Jeff >> >>> >>> >>>> De Pauw Antoine wrote: >>>> >>>> >>>>> Dear sir, >>>>> >>>>> >>>>> >>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>> Chemistry and Photophysics” section of the Université Libre de >>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>> solution, on an explanation from you here: >>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>> >>>>> >>>>> >>>>> It seems that you could help me find a solution, as I cannot plot any >>>>> points on maps. >>>>> >>>>> >>>>> >>>>> Could you please tell me what I could do to plot data in a simple way, >>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>> longitude and values to plot? >>>>> >>>>> >>>>> >>>>> Some tips would be very nice from you as any method I have tried so far >>>>> give me some errors… >>>>> >>>>> >>>>> >>>>> Thank you very much in advance, >>>>> >>>>> >>>>> >>>>> Best regards, >>>>> >>>>> >>>>> >>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>> >>>>> >>>>> >>>>> from mpl_toolkits.basemap import Basemap >>>>> >>>>> from numpy import * >>>>> >>>>> from scipy.io.numpyio import fread >>>>> >>>>> import matplotlib.pyplot as plt >>>>> >>>>> import numpy as np >>>>> >>>>> import os >>>>> >>>>> import sys >>>>> >>>>> import array >>>>> >>>>> >>>>> >>>>> fileName="c:/20080821.b56" >>>>> >>>>> >>>>> >>>>> print('preparing map') >>>>> >>>>> map = >>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>> >>>>> map.drawcoastlines(0.5,antialiased=1) >>>>> >>>>> map.drawmapboundary() >>>>> >>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>> >>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>> >>>>> print('reading binary data') >>>>> >>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>> >>>>> Lat=zeros(nbreligne) >>>>> >>>>> Lon=zeros(nbreligne) >>>>> >>>>> Val=zeros(nbreligne) >>>>> >>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>> >>>>> Lat=rawfile[0:nbreligne] >>>>> >>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>> >>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>> >>>>> print('shifting latitudes and projecting to map') >>>>> >>>>> i=0 >>>>> >>>>> while i < nbreligne: >>>>> >>>>> if(Lon[i]>180): >>>>> >>>>> print(Lon[i]) >>>>> >>>>> Lon[i]-=360 >>>>> >>>>> print(Lon[i]) >>>>> >>>>> i+=1 >>>>> >>>>> print('plotting data') >>>>> >>>>> >>>>> >>>>> #plotting code comes here >>>>> >>>>> >>>> Antoine: If you send me a self-contained script that produces the >>>> problem you see, I can help you debug it. As it stands now, I have very >>>> little to work with - it could be your plotting commands, or it could be >>>> your data. >>>> >>>> -Jeff >>>> >>>> >>>>> >>>>> >>>>> print('saving map') >>>>> >>>>> plt.savefig("testfig.png",dpi=600) >>>>> >>>>> print('done') >>>>> >>>>> >>>>> >>>>> *Antoine De Pauw* >>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>> photophysics laboratory >>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>> >>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> Meteorologist FAX : (303)497-6449 >>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>> >>>> >>>> >>>> >>> >>> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328
Ah, yes. The code was written with the assumption that the paths were treated as filled (which doesn't really matter whether they are closed or not). I have added a "filled" kwarg to Path.intersects_path and Path.intersects_bbox that when True treats the path(s) as filled, and when False does not. In order to not change existing functionality, this argument defaults to "True". To resolve Evan's problem, one would now explicitly pass "filled=False" to intersects_bbox. Cheers, Mike Eric Firing wrote: > Michael Droettboom wrote: >> I just added a test of intersects_bbox to SVN that seems to be >> working correctly for short paths containing masked values. It would >> appear that masked values *should* be dealt with correctly (that is, >> in exactly the same way as they are drawn) by the intersection code. >> However, there is probably a side case here that I'm missing. As >> Eric suggests, see if you can break it down into a simple example >> that fails and hopefully the problem and/or solution will be more >> obvious from that. > > Mike, > > I was wrong; it has nothing to do with masked values. It is much > simpler: it appears that for the purpose of this test, the path is > being treated as if it were closed. See attached. I think this > accounts for Evan's mis-identified tracks. > > Eric > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA
JJ, Thank you for sharing this. Although I have to admit I'm a bit surprised by what it takes to accomplish this, I think I will be able to use your class to do what I need to do, or at least get a lot of the way there. Cheers, -adam. On Tue, Sep 9, 2008 at 5:34 PM, Jae-Joon Lee <lee...@gm...> wrote: > Adam, > > I needed a same thing a while ago and I ended up with a custom class. > Although this need some more work, try and see if it fits your need in > case you want to avoid the little arithmetic that John mentioned. > The python file and a example plot are attached. > > I wanted the padding between the subaxes is conserved even if the > figure size changes (and something more), so the implementation got > little bit hackish and much longer than I initially expected, but it > works for me. > A simple use case is included in the file (I'm afraid that there are > not much documentation). > > > Briefly, > > > import matplotlib.pyplot as plt > from mpl_multiaxes import MultiPane_Subplot > > F = plt.figure(1) > F.clf() > > mp = MultiPane_Subplot(F, subplot_pos=(1, 1, 1), > nrows_ncols = (3, 2), > n_pane=5, > pane_direction="row", # or "column" > axes_pad_inch=0.0, > ) > > F.add_subplot(mp) > > > In the above example, MultiPane_Subplot is a subclass of the Subplot > which contains subaxes. You set number of rows and columns for your > subaxes grid. If the number of subaxes is smaller than nrows*ncols, > you explicitly set it with n_pane. > > After this, each subaxes is accessed as mp[0], mp[1], and so on. They > are subclass of Axes. So you may use any drawing method that Axes > class has. As mp is subclass of Subplot, it is also an axes. I > consider it as a kind of master axes. Anything you plot in this axes > is also drawn in all of its subaxes. Also note that xaxis and yaxis > are shared among these subaxes, therefore they have same xlim, ylim. > etc. > > Regards, > > -JJ > > > On Tue, Sep 9, 2008 at 8:12 AM, Adam <ada...@gm...> wrote: > > > > John, > > > >> By default, matplotlib will resize your axes to preserve the aspect > >> ratio of your image, which in the case of your 23x25 images is not > >> equal. You can override this behavior by setting aspect='auto' > >> > >> for i in range(6): > >> fig1.add_subplot(2,3,i+1) > >> pylab.imshow(data, aspect='auto') > > > > This gets rid of the blank space, but at the expense of the aspect ratio, > as > > you mention. Isn't there away to preserve the aspect ratios of the > > individual > > sub-images, and just remove the white space between them? I really to > not > > want to mess with the images themselves. > > > > cheers, > > adam. > > > > ------------------------------------------------------------------------- > > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > > Build the coolest Linux based applications with Moblin SDK & win great > > prizes > > Grand prize is a trip for two to an Open Source event anywhere in the > world > > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > _______________________________________________ > > Matplotlib-users mailing list > > Mat...@li... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > >
Michael Droettboom wrote: > I just added a test of intersects_bbox to SVN that seems to be working > correctly for short paths containing masked values. It would appear > that masked values *should* be dealt with correctly (that is, in exactly > the same way as they are drawn) by the intersection code. However, > there is probably a side case here that I'm missing. As Eric suggests, > see if you can break it down into a simple example that fails and > hopefully the problem and/or solution will be more obvious from that. Mike, I was wrong; it has nothing to do with masked values. It is much simpler: it appears that for the purpose of this test, the path is being treated as if it were closed. See attached. I think this accounts for Evan's mis-identified tracks. Eric
I tried pcolor, but it seems to have much higher memory usage ... the data set I'm using renders the map using contourf(x,y,z,100) relatively quickly (~10 sec) and with reasonable memory usage, and will imshow(z) even faster (although, as I said, without projection) , but pcolor(x,y,z) fails with a MemoryError after running for ~5 minutes. On Fri, Sep 5, 2008 at 6:00 AM, Michael Droettboom <md...@st...> wrote: > Erik Tollerud wrote: >> >> I've been playing with some of the projections in matplotlib, >> recently, and have some questions/noticed some odd behavior: >> >> 1. Is there any way to activate a projection mode with the pyplot >> interface other than the subplot(111,projection='whatever') method a >> la /examples/api/custom_projection_example.py ? Along these same >> lines, is the projection feature documented in greater detail >> somewhere? About everything I've figured out has come from >> custom_projection_example.py ... >> > > There is some additional documentation in the new documentation here: > > http://matplotlib.sourceforge.net/doc/html/devel/add_new_projection.html >> >> 2. I have a skymap I would like to plot using a particular projection >> - what I've been doing so far is specifying x and y coordinates using >> mgrid and calling contourf(x,y,data,100) to approximate this. But >> what I'd rather do is something like >> imshow(data,extent=[-pi,pi,-pi/2,pi/2]) ... when I call that with a >> projection axis activated, the projection isn't honored - the image >> just appears as a regular square box. Is there any way to get imshow >> to respect the projection? >> > > As Jae-Joon suggested, try pcolor. It will be slower (and there are no > interpolation options), but it should use the custom projection. imshow is > really optimized for uniform, rectilinear images. > > Cheers, > Mike > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > > -- Erik Tollerud Graduate Student Center For Cosmology Department of Physics and Astronomy 2142 Frederick Reines Hall University of California, Irvine Office Phone: (949)824-2587 Cell: (651)307-9409 eto...@uc...
Hello. I made a figure from the Postscript backend. Everything works fine except the fontweight property. I tried to set fontweight="bold" in both pylab.suptitle and pylab.text, but both of them remains in normal weight. What makes it worse is, if the title is "ubuntu-desktop", in the .ps file the title becomes just "ubuntu". However, if I set rcParam["font.weight"] in the beginning of the python file, everything becomes bold. I checked out the latest version from SVN but no luck. The fontweight property works fine in Agg backend. Thanks! _________________________________________________________________ See how Windows Mobile brings your life together—at home, work, or on the go. http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
Johann Cohen-Tanugi wrote: > thanks Eric! Could you provide me with an executive summary as to > pcolorfast vs imshow? Is it essentially a matter of speed? It is more generality than speed. imshow is for genuine image data: an array of pixel values, with the assumption that the pixels are square. imshow supports interpolation. pcolorfast works for any rectilinear grid, and depending on the characteristics of that grid, it uses the same underlying code as imshow, or a slightly slower but more general code for irregular rectangular grids (NonUniformImage), or the considerably slower quadmesh code if the grid is not rectangular. Detection of the kind of grid, and therefore the algorithm to use, is based mainly on the presence and dimensionality of the X and Y input arrays. pcolorfast does not support interpolation; it always displays quadrilaterals of uniform color. pcolorfast differs from pcolor and pcolormesh in that it does not support drawing grid boundaries, it is much faster with *agg backends, and there are some differences in the way input arguments are handled. Also, there is as yet no pyplot interface to it; I thought that some api changes might still be in order, and do not want to put pcolorfast into pyplot until its api is stable. > Also, I tried to add a colorbar but failed. What is the correct invocation? Here is one way: import numpy as np x, y = np.random.randn(2, 100000) H, xedges, yedges = np.histogram2d(x, y, bins=50) fig = figure() ax = fig.add_subplot(111) im = ax.pcolorfast(xedges, yedges, H) cb = fig.colorbar(im) draw() Eric
> That said, there has been for some time experimental functionality to > support drawing some elements "pre-rasterized" (meaning as images) to > save on file size. This is actually already working in some backends > (including PDF), it just hasn't been exposed to the user in a nice way > yet. Eric Bruning had an elegant solution to add pre/post draw > callbacks that would have really helped with this [1], but I don't know > where all that ended. The precursor thread to the one Mike linked: http://www.mail-archive.com/mat...@li.../msg02659.html I had proposed a get/set_rasterized method on each artist, and then some internal details to make sure the rasterized property was checked before the artist was drawn. That allowed raster rendering on a per-artist basis. The patch in the thread above shows the changes needed, which weren't many, so you could try to apply them if you build matplotlib yourself. I think the discussion wound up trailing off with nothing merged to trunk since there were some broader design decisions needed on event handling, etc. -Eric > It would be great to pick that ball up and get it > going again. If nothing else, it should be an easy fix to add a > "rasterized" kwarg to pcolormesh -- but I don't recall if that's the > interface that we arrived at the last time this came up. > > [1] > http://www.mail-archive.com/mat...@li.../msg03490.html > > Cheers, > Mike > > Jose Gómez-Dans wrote: >> Hi, >> In a previous email I pointed out that I was having problems with pcolormesh >> output as a PDF: the files are really big and impractical even for smallish >> arrays (1000x1000 pixels). I don't have that problem using imshow, which >> presumably resamples the image or somesuch wizardry :) Here's an example >> >> import pylab >> data = pylab.randn((512*512)).reshape((512,512)) >> #First imshow. I use the dpi keyword "just in case" >> pylab.imshow ( data, interpolation='nearest') >> pylab.savefig ("/tmp/imshow_72.pdf",dpi=72) >> pylab.savefig ("/tmp/imshow.pdf") >> #Now pcolormesh >> pylab.pcolormesh ( data ) >> pylab.savefig ("/tmp/pcolor_72.pdf",dpi=72) >> pylab.savefig ("/tmp/pcolor.pdf") >> >> This results in the following files: >> 166K /tmp/imshow_72.pdf >> 307K /tmp/imshow.pdf >> 2.6M /tmp/pcolor_72.pdf >> 2.7M /tmp/pcolor.pdf >> >> So: in the imshow case, the dpi keyword makes a difference (good!), but if you >> compare the pcolormesh and imshow filesizes you immediately notice a large >> difference. The rendering of the pcolor files is also very slow, line-by-line >> sort of thing. I presume that the different patches are stored as vectors, >> and that's why there's no change with setting dpi to 300 or to 72. >> >> Is this the expected behaviour? >> Thanks, >> J
Well, I've figured out half of it: the RGB data appears to be in <cmap>._segmentdata, an RGB-keyed dictionary of tuples of triples, but, looking at this for the jet cmap, e.g., I'm confused, 'cause the red and and blue tuples have five such triples, but the green tuple has six triples, so how exactly are these remapped to an RGB array? Thanks! DG --- On Tue, 9/9/08, David Goldsmith <d_l...@ya...> wrote: > From: David Goldsmith <d_l...@ya...> > Subject: Re: [Matplotlib-users] Next problem: pixel-to-pixel alpha variation > To: mat...@li... > Date: Tuesday, September 9, 2008, 9:15 AM > Thanks, John and Michael. > > Yeah, Michael, that's what I'm doing now, but > eventually (like, now) I'd like to do what John implies > is possible, i.e., "invert" a cm back to its RGB > table - John (or anyone) can you short-cut the learning > process for me w/ a code example of how to do this? :-) > Thanks! > > DG > --- On Tue, 9/9/08, Michael Droettboom > <md...@st...> wrote: > > > From: Michael Droettboom <md...@st...> > > Subject: Re: [Matplotlib-users] Next problem: > pixel-to-pixel alpha variation > > To: d_l...@ya... > > Cc: mat...@li... > > Date: Tuesday, September 9, 2008, 7:22 AM > > David Goldsmith wrote: > > > Hi, folks. OK, I'm trying to set the alpha > > channel, pixel by pixel, using figimage w/ the data > being of > > the "luminance" type (i.e., an MxN array). > The > > Users Guide indicates that figimage takes an alpha= > keyword > > argument, and it doesn't crash when I pass an > array for > > this value, but subsequently when I try to draw it > using > > fig.draw(canvas.get_renderer()), I get: > > > > > > > > >>>> fig.draw(canvas.get_renderer()) > > >>>> > > > Traceback (most recent call last): > > > File "<stdin>", line 1, in > > <module> > > > File > > > "C:\python25\lib\site-packages\matplotlib\figure.py", > > line 607, in draw > > > im.draw(renderer) > > > File > > > "C:\python25\lib\site-packages\matplotlib\image.py", > > line 597, in draw > > > im = self.make_image() > > > File > > > "C:\python25\lib\site-packages\matplotlib\image.py", > > line 583, in make_im > > > age > > > x = self.to_rgba(self._A, self._alpha) > > > File > > > "C:\python25\lib\site-packages\matplotlib\cm.py", > > line 76, in to_rgba > > > x = self.cmap(x, alpha=alpha, bytes=bytes) > > > File > > > "C:\python25\lib\site-packages\matplotlib\colors.py", > > line 423, in __call > > > __ > > > alpha = min(alpha, 1.0) # alpha must be > between 0 > > and 1 > > > ValueError: The truth value of an array with more > than > > one element is ambiguous. > > > Use a.any() or a.all() > > > > > > which to me "smells" as if the > array-valued > > alpha is the problem. > > > > > > Clearly (?) I can do what I'm after if I use > MxNx4 > > data, but is that the only way to have a varying > alpha? > > > > > The alpha parameter always takes only a single > (global) > > value, and the > > only way to do pixel-by-pixel alpha is an MxNx4 array. > It > > should be > > fairly straightforward to create this array by > > concatenating together > > three copies of the luminance and one copy of your > alpha, > > though. > > > > Something like: > > > > # lum is MxN, alpha is MxN > > lum = lum.reshape((M, N, 1)) > > alpha = alpha.reshape((M, N, 1)) > > rgba = numpy.concatenate((lum, lum, lum, alpha)) > > > > (There might be an even more straightforward way --- > > I'm not much of a > > numpy expert...) > > > > Cheers > > Mike > > > > -- > > Michael Droettboom > > Science Software Branch > > Operations and Engineering Division > > Space Telescope Science Institute > > Operated by AURA for NASA > > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move > Developer's challenge > Build the coolest Linux based applications with Moblin SDK > & win great prizes > Grand prize is a trip for two to an Open Source event > anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Thanks, John and Michael. Yeah, Michael, that's what I'm doing now, but eventually (like, now) I'd like to do what John implies is possible, i.e., "invert" a cm back to its RGB table - John (or anyone) can you short-cut the learning process for me w/ a code example of how to do this? :-) Thanks! DG --- On Tue, 9/9/08, Michael Droettboom <md...@st...> wrote: > From: Michael Droettboom <md...@st...> > Subject: Re: [Matplotlib-users] Next problem: pixel-to-pixel alpha variation > To: d_l...@ya... > Cc: mat...@li... > Date: Tuesday, September 9, 2008, 7:22 AM > David Goldsmith wrote: > > Hi, folks. OK, I'm trying to set the alpha > channel, pixel by pixel, using figimage w/ the data being of > the "luminance" type (i.e., an MxN array). The > Users Guide indicates that figimage takes an alpha= keyword > argument, and it doesn't crash when I pass an array for > this value, but subsequently when I try to draw it using > fig.draw(canvas.get_renderer()), I get: > > > > > >>>> fig.draw(canvas.get_renderer()) > >>>> > > Traceback (most recent call last): > > File "<stdin>", line 1, in > <module> > > File > "C:\python25\lib\site-packages\matplotlib\figure.py", > line 607, in draw > > im.draw(renderer) > > File > "C:\python25\lib\site-packages\matplotlib\image.py", > line 597, in draw > > im = self.make_image() > > File > "C:\python25\lib\site-packages\matplotlib\image.py", > line 583, in make_im > > age > > x = self.to_rgba(self._A, self._alpha) > > File > "C:\python25\lib\site-packages\matplotlib\cm.py", > line 76, in to_rgba > > x = self.cmap(x, alpha=alpha, bytes=bytes) > > File > "C:\python25\lib\site-packages\matplotlib\colors.py", > line 423, in __call > > __ > > alpha = min(alpha, 1.0) # alpha must be between 0 > and 1 > > ValueError: The truth value of an array with more than > one element is ambiguous. > > Use a.any() or a.all() > > > > which to me "smells" as if the array-valued > alpha is the problem. > > > > Clearly (?) I can do what I'm after if I use MxNx4 > data, but is that the only way to have a varying alpha? > > > The alpha parameter always takes only a single (global) > value, and the > only way to do pixel-by-pixel alpha is an MxNx4 array. It > should be > fairly straightforward to create this array by > concatenating together > three copies of the luminance and one copy of your alpha, > though. > > Something like: > > # lum is MxN, alpha is MxN > lum = lum.reshape((M, N, 1)) > alpha = alpha.reshape((M, N, 1)) > rgba = numpy.concatenate((lum, lum, lum, alpha)) > > (There might be an even more straightforward way --- > I'm not much of a > numpy expert...) > > Cheers > Mike > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA
Adam, I needed a same thing a while ago and I ended up with a custom class. Although this need some more work, try and see if it fits your need in case you want to avoid the little arithmetic that John mentioned. The python file and a example plot are attached. I wanted the padding between the subaxes is conserved even if the figure size changes (and something more), so the implementation got little bit hackish and much longer than I initially expected, but it works for me. A simple use case is included in the file (I'm afraid that there are not much documentation). Briefly, import matplotlib.pyplot as plt from mpl_multiaxes import MultiPane_Subplot F = plt.figure(1) F.clf() mp = MultiPane_Subplot(F, subplot_pos=(1, 1, 1), nrows_ncols = (3, 2), n_pane=5, pane_direction="row", # or "column" axes_pad_inch=0.0, ) F.add_subplot(mp) In the above example, MultiPane_Subplot is a subclass of the Subplot which contains subaxes. You set number of rows and columns for your subaxes grid. If the number of subaxes is smaller than nrows*ncols, you explicitly set it with n_pane. After this, each subaxes is accessed as mp[0], mp[1], and so on. They are subclass of Axes. So you may use any drawing method that Axes class has. As mp is subclass of Subplot, it is also an axes. I consider it as a kind of master axes. Anything you plot in this axes is also drawn in all of its subaxes. Also note that xaxis and yaxis are shared among these subaxes, therefore they have same xlim, ylim. etc. Regards, -JJ On Tue, Sep 9, 2008 at 8:12 AM, Adam <ada...@gm...> wrote: > > John, > >> By default, matplotlib will resize your axes to preserve the aspect >> ratio of your image, which in the case of your 23x25 images is not >> equal. You can override this behavior by setting aspect='auto' >> >> for i in range(6): >> fig1.add_subplot(2,3,i+1) >> pylab.imshow(data, aspect='auto') > > This gets rid of the blank space, but at the expense of the aspect ratio, as > you mention. Isn't there away to preserve the aspect ratios of the > individual > sub-images, and just remove the white space between them? I really to not > want to mess with the images themselves. > > cheers, > adam. > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > >
Ok, I'm stupid, changing the resolution value and all goes right. Sorry Lionel Roubeyrie a écrit : > Hi all, > the new polar projection gives me a strange behavour by interpolating > each simple line between two consecutives points. Where I just want > points at specified coordinates and lines connecting them, between each > pairs appears a interpolated line in polar projection with multiple points. > Looking in the documentation doesn't give an alternative. Is there a way > to have just "simples" lines? > thanks > > ################## > from pylab import * > theta = arange(0, 360, 36) > r = [5,1] * (len(theta)/2) > polar(radians(theta), r, 'o-') > show() > ################## > -- Lionel Roubeyrie - lro...@li... Chargé d'études et de maintenance LIMAIR - la Surveillance de l'Air en Limousin http://www.limair.asso.fr
pcolormesh is outputting the data as vectors, since the mesh can be non-rectilinear, that's really the only thing that PDF supports. Besides, that's the only way to get a truly resolution-independent PDF. Since imshow is limited to uniform, rectilinear images, and PDF has built-in support for those, the file is much smaller and the drawing more efficient. That said, there has been for some time experimental functionality to support drawing some elements "pre-rasterized" (meaning as images) to save on file size. This is actually already working in some backends (including PDF), it just hasn't been exposed to the user in a nice way yet. Eric Bruning had an elegant solution to add pre/post draw callbacks that would have really helped with this [1], but I don't know where all that ended. It would be great to pick that ball up and get it going again. If nothing else, it should be an easy fix to add a "rasterized" kwarg to pcolormesh -- but I don't recall if that's the interface that we arrived at the last time this came up. [1] http://www.mail-archive.com/mat...@li.../msg03490.html Cheers, Mike Jose Gómez-Dans wrote: > Hi, > In a previous email I pointed out that I was having problems with pcolormesh > output as a PDF: the files are really big and impractical even for smallish > arrays (1000x1000 pixels). I don't have that problem using imshow, which > presumably resamples the image or somesuch wizardry :) Here's an example > > import pylab > data = pylab.randn((512*512)).reshape((512,512)) > #First imshow. I use the dpi keyword "just in case" > pylab.imshow ( data, interpolation='nearest') > pylab.savefig ("/tmp/imshow_72.pdf",dpi=72) > pylab.savefig ("/tmp/imshow.pdf") > #Now pcolormesh > pylab.pcolormesh ( data ) > pylab.savefig ("/tmp/pcolor_72.pdf",dpi=72) > pylab.savefig ("/tmp/pcolor.pdf") > > This results in the following files: > 166K /tmp/imshow_72.pdf > 307K /tmp/imshow.pdf > 2.6M /tmp/pcolor_72.pdf > 2.7M /tmp/pcolor.pdf > > So: in the imshow case, the dpi keyword makes a difference (good!), but if you > compare the pcolormesh and imshow filesizes you immediately notice a large > difference. The rendering of the pcolor files is also very slow, line-by-line > sort of thing. I presume that the different patches are stored as vectors, > and that's why there's no change with setting dpi to 300 or to 72. > > Is this the expected behaviour? > Thanks, > J > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA