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
(5) |
2
(6) |
3
(4) |
4
(9) |
5
(7) |
6
(16) |
7
(5) |
8
(10) |
9
(2) |
10
(3) |
11
(9) |
12
(1) |
13
(13) |
14
(1) |
15
(13) |
16
(5) |
17
(3) |
18
(14) |
19
(17) |
20
(14) |
21
(15) |
22
(6) |
23
(6) |
24
|
25
(4) |
26
(4) |
27
(4) |
28
(11) |
29
(7) |
30
(1) |
I have now tested this with version 1.1.0svn from the trunk of the dev repository. I believe this version contains Michael Droettboo's patch for pyCXX. ( https://sourceforge.net/tracker/index.php?func=detail&aid=3115633&group_id=3180&atid=103180) Unfortunately the leak is still evident in the small script I've attached. Again, please note that this script has no axes, plots, or drawn components, only an empty canvas that is being redrawn and causes the memory growth. Any ideas how to resolve this or further debug this? Thanks for your help, Oren On Mon, Apr 11, 2011 at 6:37 PM, Oren Gampel <or...@fu...> wrote: > I'm having a memory leakage using matplotlib 1.0.1 with wx 2.8.11.0, on > windows XP. > > To reproduce, I used the sample from here: > http://matplotlib.sourceforge.net/examples/animation/dynamic_image_wxagg2.htmland deleted most of the significant lines (see below). I only create a > canvas but I don't create any axes, nor plot any data. > The only thing I do is draw() on a timer event. This makes my process grow > about 6Mbyte per minute. > > Is this reproduced in other environments? Any ideas on how to resolve this? > > Thanks, > Oren > > > """ > Copyright (C) 2003-2005 Jeremy O'Donoghue and others > > License: This work is licensed under the PSF. A copy should be included > with this source code, and is also available at > http://www.python.org/psf/license.html > > """ > import sys, time, os, gc > > import matplotlib > matplotlib.use('WXAgg') > > from matplotlib import rcParams > import numpy as npy > > import matplotlib.cm as cm > > from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg > from matplotlib.backends.backend_wx import NavigationToolbar2Wx > > from matplotlib.figure import Figure > from wx import * > > > TIMER_ID = NewId() > > class PlotFigure(Frame): > > def __init__(self): > Frame.__init__(self, None, -1, "Test embedded wxFigure") > > self.fig = Figure((1,1), 50, facecolor='.95') > self.canvas = FigureCanvasWxAgg(self, -1, self.fig) > # Now put all into a sizer > sizer = wx.BoxSizer(wx.VERTICAL) > # This way of adding to sizer allows resizing > sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW) > self.SetSizer(sizer) > self.Fit() > > self._price_ax = self.fig.add_subplot(111) > > > wx.EVT_TIMER(self, TIMER_ID, self.onTimer) > self.t = wx.Timer(self, TIMER_ID) > self.t.Start(1000) > > def onTimer(self, evt): > self.canvas.draw() > > > if __name__ == '__main__': > app = PySimpleApp() > frame = PlotFigure() > # Initialise the timer - wxPython requires this to be connected to > # the receiving event handler > t = Timer(frame, TIMER_ID) > t.Start(100) > > frame.Show() > app.MainLoop() > >
These commands plot points on a map in my code using python, matplotlib, and basemap. Thanks to Ian and Glenn for their assistance. Turns out lat, lon needed to be transformed into Lambert's coordinate space upon which the rest of the map is based. If anyone knows of a more elegant way to work on the entire array, rather than each point, I'll give it a shot. Mike data = csv2rec('file2.txt',delimiter=',',names=['lat','lon']) for i in range(len(data)): x,y=m(data['lon'][i],data['lat'][i]) # Translate to basemap's (Lambert) coordinate space plot(x,y,color='black',marker='.',markersize=6.0)
On 04/20/2011 11:27 AM, Caleb Constantine wrote: > On Wed, Apr 20, 2011 at 9:29 AM, Michael Droettboom<md...@st...> wrote: >> On 04/20/2011 07:48 AM, Caleb Constantine wrote: >>> On Tue, Apr 19, 2011 at 2:25 PM, Michael Droettboom<md...@st...> wrote: >>>> Ok. I have a RHEL5 Linux box with Python 2.7.1. >>>> >>>> With Numpy 1.4.1 and 1.5.1 I don't see any leaks. With Numpy git HEAD, >>>> I did see a leak -- I submitted a pull request to Numpy here: >>>> >>>> https://github.com/numpy/numpy/pull/76 >>>> >>>> I get the same results (no leaks) running your wx, tk and agg scripts >>>> (with the Windows-specific stuff removed). >>>> >>>> FWIW, I have wxPython 2.8.11.0 and Tkinter rev 81008. >>>> >>>> So the variables are the platform and the version of Python. Perhaps >>>> it's one of those two things? >>>> >>>> Mike >>> Consider the following: >>> >>> matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, >>> Windows XP SP3 >>> >>> - 1 hour >>> - Plotted 3601 times, about 1Hz >>> - Memory usage increased by about 1.16MB (41.39 - 40.23), or >>> about 0.33K per redraw >>> >>> It seems the same memory leak exists. Given you don't have this issue >>> on Linux with the same Python configuration, I can only assume it is >>> related to some Windows specific code somewhere. I'll run for a longer >>> period of time just in case, but I don't expect the results to be >>> different. >> One way to rule out Windows-specific code may be to run with the Agg >> backend only (without wx). Have you plotted the memory growth? This >> amount of memory growth is well within the pool allocation sizes that >> Python routinely uses. Does the value of len(gc.get_objects()) grow >> over time? >> > New results follows. > > matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, Windows XP SP3 > > agg > - 3601 redraws (1 hour), about 1Hz > - Memory usage: 28.79 - 27.57 = 1.22 MB > - len(gc.get_objects()): 23424 at beginning and end > - Plot of memory growth: roughly linear, increasing with slope of 0.26KB > > tkagg > - 3601 redraws (1 hour), about 1Hz > - Memory usage: 33.22 - 33.32 = -0.1 MB > - len(gc.get_objects()): 24182 at beginning and end > - Plot of memory growth: very irregular (up and down), but a line fit > has a slope of about 0.025KB (I could run longer and see if slope > approaches 0) > > wxagg > - 3601 redraws (1 hour), about 1Hz > - Memory usage: 43.28 - 41.80 = 1.5 MB > - len(gc.get_objects()): 41473 at beginning and end > - Plot of memory growth: roughly linear, increasing with slope of 0.32KB Thanks. These are very useful results. The fact that gc.get_objects() remains constant suggests to me that this is not a simple case of holding on to a Python reference longer than we intend to. Instead, this is either a C-side reference counting bug, or a genuine C malloc-and-never-free bug. Puzzlingly, valgrind usually does a very good job of finding such bugs, but is turning up nothing for me. Will have to scratch my head a little bit longer and see if I can come up with a proper experiment that will help me get to the bottom of this. Cheers, Mike
On Wed, Apr 20, 2011 at 9:29 AM, Michael Droettboom <md...@st...> wrote: > On 04/20/2011 07:48 AM, Caleb Constantine wrote: >> On Tue, Apr 19, 2011 at 2:25 PM, Michael Droettboom<md...@st...> wrote: >>> Ok. I have a RHEL5 Linux box with Python 2.7.1. >>> >>> With Numpy 1.4.1 and 1.5.1 I don't see any leaks. With Numpy git HEAD, >>> I did see a leak -- I submitted a pull request to Numpy here: >>> >>> https://github.com/numpy/numpy/pull/76 >>> >>> I get the same results (no leaks) running your wx, tk and agg scripts >>> (with the Windows-specific stuff removed). >>> >>> FWIW, I have wxPython 2.8.11.0 and Tkinter rev 81008. >>> >>> So the variables are the platform and the version of Python. Perhaps >>> it's one of those two things? >>> >>> Mike >> Consider the following: >> >> matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, >> Windows XP SP3 >> >> - 1 hour >> - Plotted 3601 times, about 1Hz >> - Memory usage increased by about 1.16MB (41.39 - 40.23), or >> about 0.33K per redraw >> >> It seems the same memory leak exists. Given you don't have this issue >> on Linux with the same Python configuration, I can only assume it is >> related to some Windows specific code somewhere. I'll run for a longer >> period of time just in case, but I don't expect the results to be >> different. > One way to rule out Windows-specific code may be to run with the Agg > backend only (without wx). Have you plotted the memory growth? This > amount of memory growth is well within the pool allocation sizes that > Python routinely uses. Does the value of len(gc.get_objects()) grow > over time? > New results follows. matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, Windows XP SP3 agg - 3601 redraws (1 hour), about 1Hz - Memory usage: 28.79 - 27.57 = 1.22 MB - len(gc.get_objects()): 23424 at beginning and end - Plot of memory growth: roughly linear, increasing with slope of 0.26KB tkagg - 3601 redraws (1 hour), about 1Hz - Memory usage: 33.22 - 33.32 = -0.1 MB - len(gc.get_objects()): 24182 at beginning and end - Plot of memory growth: very irregular (up and down), but a line fit has a slope of about 0.025KB (I could run longer and see if slope approaches 0) wxagg - 3601 redraws (1 hour), about 1Hz - Memory usage: 43.28 - 41.80 = 1.5 MB - len(gc.get_objects()): 41473 at beginning and end - Plot of memory growth: roughly linear, increasing with slope of 0.32KB
On 04/20/2011 07:48 AM, Caleb Constantine wrote: > On Tue, Apr 19, 2011 at 2:25 PM, Michael Droettboom<md...@st...> wrote: >> Ok. I have a RHEL5 Linux box with Python 2.7.1. >> >> With Numpy 1.4.1 and 1.5.1 I don't see any leaks. With Numpy git HEAD, >> I did see a leak -- I submitted a pull request to Numpy here: >> >> https://github.com/numpy/numpy/pull/76 >> >> I get the same results (no leaks) running your wx, tk and agg scripts >> (with the Windows-specific stuff removed). >> >> FWIW, I have wxPython 2.8.11.0 and Tkinter rev 81008. >> >> So the variables are the platform and the version of Python. Perhaps >> it's one of those two things? >> >> Mike > Consider the following: > > matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, > Windows XP SP3 > > - 1 hour > - Plotted 3601 times, about 1Hz > - Memory usage increased by about 1.16MB (41.39 - 40.23), or > about 0.33K per redraw > > It seems the same memory leak exists. Given you don't have this issue > on Linux with the same Python configuration, I can only assume it is > related to some Windows specific code somewhere. I'll run for a longer > period of time just in case, but I don't expect the results to be > different. One way to rule out Windows-specific code may be to run with the Agg backend only (without wx). Have you plotted the memory growth? This amount of memory growth is well within the pool allocation sizes that Python routinely uses. Does the value of len(gc.get_objects()) grow over time? Mike
On Tue, Apr 19, 2011 at 2:25 PM, Michael Droettboom <md...@st...> wrote: > Ok. I have a RHEL5 Linux box with Python 2.7.1. > > With Numpy 1.4.1 and 1.5.1 I don't see any leaks. With Numpy git HEAD, > I did see a leak -- I submitted a pull request to Numpy here: > > https://github.com/numpy/numpy/pull/76 > > I get the same results (no leaks) running your wx, tk and agg scripts > (with the Windows-specific stuff removed). > > FWIW, I have wxPython 2.8.11.0 and Tkinter rev 81008. > > So the variables are the platform and the version of Python. Perhaps > it's one of those two things? > > Mike Consider the following: matplotlib 1.0.1, numpy 1.5.1, python 2.7.1, wxPython 2.8.11.0, Windows XP SP3 - 1 hour - Plotted 3601 times, about 1Hz - Memory usage increased by about 1.16MB (41.39 - 40.23), or about 0.33K per redraw It seems the same memory leak exists. Given you don't have this issue on Linux with the same Python configuration, I can only assume it is related to some Windows specific code somewhere. I'll run for a longer period of time just in case, but I don't expect the results to be different.
Hi, On 2011年4月19日 13:09:23 -0700 (PDT) Michael Rawlins <raw...@ya...> wrote: > I'm reading > the latitudes and longitudes from a file, with each lat, lon pair on > each record (line). I use loadtxt for this purpose. http://www.scipy.org/Cookbook/InputOutput http://www.neuralwiki.org/index.php?title=Loading_data_with_python Heiko -- -- Autoren sollten stehend an einem Pult schreiben. Dann würden -- ihnen ganz von selbst kurze Sätze einfallen. -- (Ernest Hemingway, 1899-1961) -- Number Crunch Blog @ http://numbercrunch.de
Greetings, I'm trying to use Matplotlib to plot 3d surfaces, with good results. While the plot are nice, there is little information on the website about customizing them. To get what I want, I used some tricks and hacks, and I am pretty sure that there are better ways to do it. Here is what I did, if you have any advice on how to do it better. * The wireframe lines in the surface are thicker than I wanted. I couldn't find a way to configure their thickness. To get thinner lines, I made my plots huge (about 24 inches), and adjusted fonts accordingly. This is a very ugly (and unpredictable) hack. * I need gray images, so I used the gray colormap. This, however, gave me very dark and bright areas, and I wanted a little less variation. Since my functions always range from 0. to 1., I set vmin=-1 and vmax=2. I got the result I wanted, but I feel that there is a better way to do that. * The grids on the 'walls' and 'floor', on the other hand, are very bright, and I wanted them darker. Couldn't find a way to do that. * In some plots, I don't want ticks on some axis. Setting ticks to [] gave me no result, and there is no method for that in the z-axis. Setting ticklabels to [] also made no difference. Is there a way to remove the ticks or the labels in 3d plots? I figure out that there is probably ways to do all those by handling the corresponding Artists, or other object of the kind. But they are full of details, and I don't know exactly where to start. Any directions will be appreciated. I've been using matplotlib for years, and it is always helpful, and the plots are always beautiful. Thanks for the nice work. --- José Alexandre Nalon na...@te...
Thanks Glenn and Ian. I have just explicitly set delimiter=',' but still no points plotted. I'm new to this software so will look into using ipython --pylab and documentation. For the short term I will just create in a shell script 200 strings/records with the lat,lon inserted in the plot command and paste them into the source code. Not ideal but will get the job done. Mike --- On Tue, 4/19/11, G Jones <gle...@gm...> wrote: From: G Jones <gle...@gm...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: "Ian Bell" <ib...@pu...>, Mat...@li... Date: Tuesday, April 19, 2011, 8:31 PM As you can see from the error message, it's trying to convert "39.4670," to a float and complaining that this is not a valid value (because of the comma. The examples I suggested were for your original space delimited data. For comma delimited data you'll want to remove the delimiter argument to csv2rec (or explicitly set delimiter=',' if you prefer). If you want to use loadtxt, you can set delimiter=',' Again, read the doc strings to see what these functions are expecting by default. On Tue, Apr 19, 2011 at 5:26 PM, Michael Rawlins <raw...@ya...> wrote: The first example produced no plotted symbols but no errors on execution. The second example produced this: Plotting, please wait...maybe more than 10 seconds Traceback (most recent call last): File "testNew.py", line 137, in <module> data = np.loadtxt('file2.txt') File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 489, in loadtxt X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)])) ValueError: invalid literal for float(): 39.4670, Grrrr...... My code follows. I believe this is standard python and matplotlib. Should produce a map of Northeast US. Perhaps someone could get this working with a few example points: 39.4670, -76.1670 46.4000, -74.7670 45.3830, -75.7170 43.6170, -79.3830 45.5170, -73.4170 45.6170, -74.4170 43.8330, -77.1500 43.9500, -78.1670 43.2500, -79.2170 43.8330, -66.0830 #!/usr/bin/env python # v0.5 19 June 2010 # General purpose plotter of 2-D gridded data from NetCDF files, # plotted with map boundaries. # NetCDF file should have data in either 2-D, 3-D or 4-D arrays. # Works with the netCDF files in the tutorial, and also the # files available for download at: # http://www.cdc.noaa.gov/cdc/data.ncep.reanalysis.html # Adapted from the basemap example plotmap_pcolor.py, # Some of the variable names from that example are retained. # # Uses basemap's pcolor function. Pcolor accepts arrays # of the longitude and latitude points of the vertices on the pixels, # as well as an array with the numerical value in the pixel. verbose=0 #verbose=2 says a bit more import sys,getopt from mpl_toolkits.basemap import Basemap, shiftgrid, cm #from netCDF3 import Dataset as NetCDFFile from mpl_toolkits.basemap import NetCDFFile from pylab import * #from matplotlib.mlab import csv2rec alloptions, otherargs= getopt.getopt(sys.argv[1:],'ro:p:X:Y:v:t:l:u:n:') # note the : after o and p proj='lam' #plotfile=None #plotfile='testmap2.png' usejetrev=False colorbounds=[None,None] extratext="" xvar=None yvar=None thevar=None therec=None thelev=None cbot=None ctop=None startlon=-180 #default assumption for starting longitude for theopt,thearg in alloptions: print theopt,thearg if theopt=='-o': # -o needs filename after it, which is now thearg plotfile=thearg elif theopt=='-p': proj=thearg elif theopt=='-X': xvar=thearg elif theopt=='-Y': yvar=thearg elif theopt=='-v': thevar=thearg elif theopt=='-t': thetitle=thearg elif theopt=='-l': cbot=thearg elif theopt=='-u': ctop=thearg elif theopt=='-n': therec=thearg elif theopt=='-m': thelev=thearg elif theopt=='-r': usejetrev=True else: #something went wrong print "hmm, what are these??? ", theopt, thearg sys.exit() print "\nPlotting, please wait...maybe more than 10 seconds" if proj=='lam': #Lambert Conformal m = Basemap(llcrnrlon=-80.6,llcrnrlat=38.4,urcrnrlon=-66.0,urcrnrlat=47.7,\ resolution='l',area_thresh=1000.,projection='lcc',\ lat_1=65.,lon_0=-73.3) xtxt=200000. #offset for text ytxt=200000. parallels = arange(38.,48.,4.) meridians = arange(-80.,-68.,4.) else: #cylindrical is default # m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\ # resolution='c',area_thresh=10000.,projection='cyl') m = Basemap(llcrnrlon=startlon,llcrnrlat=-90,urcrnrlon=startlon+360.,urcrnrlat=90.,\ resolution='c',area_thresh=10000.,projection='cyl') xtxt=1. ytxt=0. parallels = arange(-90.,90.,30.) if startlon==-180: meridians = arange(-180.,180.,60.) else: meridians = arange(0.,360.,60.) if verbose>1: print m.__doc__ xsize = rcParams['figure.figsize'][0] fig=figure(figsize=(xsize,m.aspect*xsize)) #ax = fig.add_axes([0.08,0.1,0.7,0.7],axisbg='white') ax = fig.add_axes([0.06,0.00,0.8,1.0],axisbg='white') # make a pcolor plot. #x, y = m(lons, lats) #p = m.pcolor(x,y,maskdat,shading='flat',cmap=cmap) #clim(*colorbounds) # axes units units are left, bottom, width, height #cax = axes([0.85, 0.1, 0.05, 0.7]) # colorbar axes for map w/ no graticule cax = axes([0.88, 0.1, 0.06, 0.81]) # colorbar axes for map w/ graticule axes(ax) # make the original axes current again ######### Plot symbol at station locations ################# #lines=open('file2.txt','r').readlines() #(lats,lons)=([],[]) #for line in lines: # (lat,lon)=line.strip().split(',') # lats.append(float(lat)) # lons.append(float(lon)) #for i in range(len(lons)): # plt.plot(lats,lons,'*') #plt.plot(lons,lats,'*') #data = csv2rec('file2.txt',delimiter=',') #plot(data[:,0],data[:,1],'o') #data = csv2rec('file2.txt',delimiter=' ',names=['lat','lon']) #plot(data['lat'],data['lon'],'o') data = np.loadtxt('file2.txt') plot(data[:,0],data[:,1],'o') xpt,ypt = m(-75.0,43.0) text(xpt,ypt,'*') # draw coastlines and political boundaries. m.drawcoastlines() m.drawcountries() m.drawstates() # draw parallels and meridians. # label on left, right and bottom of map. m.drawparallels(parallels,labels=[1,0,0,0]) m.drawmeridians(meridians,labels=[1,1,0,1]) #if plotfile: # savefig(plotfile, dpi=72, facecolor='w', bbox_inches='tight', edgecolor='w', orientation='portrait') #else: # show() #plt.savefig('map.png') plt.savefig('map.eps') # comment show to mass produce --- On Tue, 4/19/11, G Jones <gle...@gm...> wrote: From: G Jones <gle...@gm...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: "Ian Bell" <ib...@pu...>, Mat...@li... Date: Tuesday, April 19, 2011, 8:12 PM No need for a header, but I guess my example was a little too simple. You could do: data = csv2rec(filename,delimiter=' ',names=['lat','lon']) plot(data['lat'],data['lon'],'o') or you could do data = np.loadtxt(filename) plot(data[:,0],data[:,1],'o') In general, I strongly recommend developing with ipython --pylab. That way all the documentation is at your fingertips using the ? and ?? notation.
As you can see from the error message, it's trying to convert "39.4670," to a float and complaining that this is not a valid value (because of the comma. The examples I suggested were for your original space delimited data. For comma delimited data you'll want to remove the delimiter argument to csv2rec (or explicitly set delimiter=',' if you prefer). If you want to use loadtxt, you can set delimiter=',' Again, read the doc strings to see what these functions are expecting by default. On Tue, Apr 19, 2011 at 5:26 PM, Michael Rawlins <raw...@ya...>wrote: > > The first example produced no plotted symbols but no errors on execution. > The second example produced this: > > Plotting, please wait...maybe more than 10 seconds > > Traceback (most recent call last): > File "testNew.py", line 137, in <module> > data = np.loadtxt('file2.txt') > File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 489, in > loadtxt > X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)])) > ValueError: invalid literal for float(): 39.4670, > > > Grrrr...... > > My code follows. I believe this is standard python and matplotlib. Should > produce a map of Northeast US. Perhaps someone could get this working with > a few example points: > > > 39.4670, -76.1670 > 46.4000, -74.7670 > 45.3830, -75.7170 > 43.6170, -79.3830 > 45.5170, -73.4170 > 45.6170, -74.4170 > 43.8330, -77.1500 > 43.9500, -78.1670 > 43.2500, -79.2170 > 43.8330, -66.0830 > > > #!/usr/bin/env python > # v0.5 19 June 2010 > # General purpose plotter of 2-D gridded data from NetCDF files, > # plotted with map boundaries. > # NetCDF file should have data in either 2-D, 3-D or 4-D arrays. > # Works with the netCDF files in the tutorial, and also the > # files available for download at: > # http://www.cdc.noaa.gov/cdc/data.ncep.reanalysis.html > # Adapted from the basemap example plotmap_pcolor.py, > # Some of the variable names from that example are retained. > # > # Uses basemap's pcolor function. Pcolor accepts arrays > # of the longitude and latitude points of the vertices on the pixels, > # as well as an array with the numerical value in the pixel. > > verbose=0 #verbose=2 says a bit more > > > import sys,getopt > > from mpl_toolkits.basemap import Basemap, shiftgrid, cm > #from netCDF3 import Dataset as NetCDFFile > from mpl_toolkits.basemap import NetCDFFile > from pylab import * > #from matplotlib.mlab import csv2rec > > alloptions, otherargs= getopt.getopt(sys.argv[1:],'ro:p:X:Y:v:t:l:u:n:') # > note the : after o and p > proj='lam' > #plotfile=None > #plotfile='testmap2.png' > usejetrev=False > colorbounds=[None,None] > extratext="" > xvar=None > yvar=None > thevar=None > > therec=None > thelev=None > cbot=None > ctop=None > startlon=-180 #default assumption for starting longitude > for theopt,thearg in alloptions: > print theopt,thearg > if theopt=='-o': # -o needs filename after it, which is now thearg > plotfile=thearg > elif theopt=='-p': > proj=thearg > elif theopt=='-X': > xvar=thearg > elif theopt=='-Y': > yvar=thearg > elif theopt=='-v': > thevar=thearg > elif theopt=='-t': > thetitle=thearg > elif theopt=='-l': > cbot=thearg > elif theopt=='-u': > ctop=thearg > elif theopt=='-n': > therec=thearg > elif theopt=='-m': > thelev=thearg > elif theopt=='-r': > usejetrev=True > else: #something went wrong > print "hmm, what are these??? ", theopt, thearg > sys.exit() > > print "\nPlotting, please wait...maybe more than 10 seconds" > if proj=='lam': #Lambert Conformal > m = > Basemap(llcrnrlon=-80.6,llcrnrlat=38.4,urcrnrlon=-66.0,urcrnrlat=47.7,\ > resolution='l',area_thresh=1000.,projection='lcc',\ > lat_1=65.,lon_0=-73.3) > xtxt=200000. #offset for text > ytxt=200000. > parallels = arange(38.,48.,4.) > meridians = arange(-80.,-68.,4.) > else: #cylindrical is default > # m = > Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\ > # resolution='c',area_thresh=10000.,projection='cyl') > m = > Basemap(llcrnrlon=startlon,llcrnrlat=-90,urcrnrlon=startlon+360.,urcrnrlat=90.,\ > resolution='c',area_thresh=10000.,projection='cyl') > xtxt=1. > ytxt=0. > parallels = arange(-90.,90.,30.) > if startlon==-180: > meridians = arange(-180.,180.,60.) > else: > meridians = arange(0.,360.,60.) > > if verbose>1: print m.__doc__ > xsize = rcParams['figure.figsize'][0] > fig=figure(figsize=(xsize,m.aspect*xsize)) > #ax = fig.add_axes([0.08,0.1,0.7,0.7],axisbg='white') > ax = fig.add_axes([0.06,0.00,0.8,1.0],axisbg='white') > # make a pcolor plot. > #x, y = m(lons, lats) > #p = m.pcolor(x,y,maskdat,shading='flat',cmap=cmap) > #clim(*colorbounds) > > # axes units units are left, bottom, width, height > #cax = axes([0.85, 0.1, 0.05, 0.7]) # colorbar axes for map w/ no > graticule > cax = axes([0.88, 0.1, 0.06, 0.81]) # colorbar axes for map w/ graticule > > axes(ax) # make the original axes current again > > ######### Plot symbol at station locations ################# > > #lines=open('file2.txt','r').readlines() > > #(lats,lons)=([],[]) > #for line in lines: > # (lat,lon)=line.strip().split(',') > # lats.append(float(lat)) > # lons.append(float(lon)) > > #for i in range(len(lons)): > # plt.plot(lats,lons,'*') > > #plt.plot(lons,lats,'*') > > #data = csv2rec('file2.txt',delimiter=',') > > #plot(data[:,0],data[:,1],'o') > > #data = csv2rec('file2.txt',delimiter=' ',names=['lat','lon']) > > #plot(data['lat'],data['lon'],'o') > > data = np.loadtxt('file2.txt') > > plot(data[:,0],data[:,1],'o') > > xpt,ypt = m(-75.0,43.0) > text(xpt,ypt,'*') > > > # draw coastlines and political boundaries. > m.drawcoastlines() > m.drawcountries() > m.drawstates() > # draw parallels and meridians. > # label on left, right and bottom of map. > m.drawparallels(parallels,labels=[1,0,0,0]) > m.drawmeridians(meridians,labels=[1,1,0,1]) > > #if plotfile: > # savefig(plotfile, dpi=72, facecolor='w', bbox_inches='tight', > edgecolor='w', orientation='portrait') > #else: > # show() > > #plt.savefig('map.png') > plt.savefig('map.eps') > # comment show to mass produce > > > > > --- On *Tue, 4/19/11, G Jones <gle...@gm...>* wrote: > > > From: G Jones <gle...@gm...> > > Subject: Re: [Matplotlib-users] plotting points/locations from data file > To: "Michael Rawlins" <raw...@ya...> > Cc: "Ian Bell" <ib...@pu...>, Mat...@li... > Date: Tuesday, April 19, 2011, 8:12 PM > > > No need for a header, but I guess my example was a little too simple. You > could do: > data = csv2rec(filename,delimiter=' ',names=['lat','lon']) > plot(data['lat'],data['lon'],'o') > > or you could do > data = np.loadtxt(filename) > plot(data[:,0],data[:,1],'o') > > In general, I strongly recommend developing with ipython --pylab. That way > all the documentation is at your fingertips using the ? and ?? notation. > >
On second thought, the code requires basemap package too. Mike --- On Tue, 4/19/11, Michael Rawlins <raw...@ya...> wrote: From: Michael Rawlins <raw...@ya...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "G Jones" <gle...@gm...> Cc: Mat...@li... Date: Tuesday, April 19, 2011, 8:26 PM The first example produced no plotted symbols but no errors on execution. The second example produced this: Plotting, please wait...maybe more than 10 seconds Traceback (most recent call last): File "testNew.py", line 137, in <module> data = np.loadtxt('file2.txt') File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 489, in loadtxt X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)])) ValueError: invalid literal for float(): 39.4670, Grrrr...... My code follows. I believe this is standard python and matplotlib. Should produce a map of Northeast US. Perhaps someone could get this working with a few example points: 39.4670, -76.1670 46.4000, -74.7670 45.3830, -75.7170 43.6170, -79.3830 45.5170, -73.4170 45.6170, -74.4170 43.8330, -77.1500 43.9500, -78.1670 43.2500, -79.2170 43.8330, -66.0830 #!/usr/bin/env python # v0.5 19 June 2010 # General purpose plotter of 2-D gridded data from NetCDF files, # plotted with map boundaries. # NetCDF file should have data in either 2-D, 3-D or 4-D arrays. # Works with the netCDF files in the tutorial, and also the # files available for download at: # http://www.cdc.noaa.gov/cdc/data.ncep.reanalysis.html # Adapted from the basemap example plotmap_pcolor.py, # Some of the variable names from that example are retained. # # Uses basemap's pcolor function. Pcolor accepts arrays # of the longitude and latitude points of the vertices on the pixels, # as well as an array with the numerical value in the pixel. verbose=0 #verbose=2 says a bit more import sys,getopt from mpl_toolkits.basemap import Basemap, shiftgrid, cm #from netCDF3 import Dataset as NetCDFFile from mpl_toolkits.basemap import NetCDFFile from pylab import * #from matplotlib.mlab import csv2rec alloptions, otherargs= getopt.getopt(sys.argv[1:],'ro:p:X:Y:v:t:l:u:n:') # note the : after o and p proj='lam' #plotfile=None #plotfile='testmap2.png' usejetrev=False colorbounds=[None,None] extratext="" xvar=None yvar=None thevar=None therec=None thelev=None cbot=None ctop=None startlon=-180 #default assumption for starting longitude for theopt,thearg in alloptions: print theopt,thearg if theopt=='-o': # -o needs filename after it, which is now thearg plotfile=thearg elif theopt=='-p': proj=thearg elif theopt=='-X': xvar=thearg elif theopt=='-Y': yvar=thearg elif theopt=='-v': thevar=thearg elif theopt=='-t': thetitle=thearg elif theopt=='-l': cbot=thearg elif theopt=='-u': ctop=thearg elif theopt=='-n': therec=thearg elif theopt=='-m': thelev=thearg elif theopt=='-r': usejetrev=True else: #something went wrong print "hmm, what are these??? ", theopt, thearg sys.exit() print "\nPlotting, please wait...maybe more than 10 seconds" if proj=='lam': #Lambert Conformal m = Basemap(llcrnrlon=-80.6,llcrnrlat=38.4,urcrnrlon=-66.0,urcrnrlat=47.7,\ resolution='l',area_thresh=1000.,projection='lcc',\ lat_1=65.,lon_0=-73.3) xtxt=200000. #offset for text ytxt=200000. parallels = arange(38.,48.,4.) meridians = arange(-80.,-68.,4.) else: #cylindrical is default # m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\ # resolution='c',area_thresh=10000.,projection='cyl') m = Basemap(llcrnrlon=startlon,llcrnrlat=-90,urcrnrlon=startlon+360.,urcrnrlat=90.,\ resolution='c',area_thresh=10000.,projection='cyl') xtxt=1. ytxt=0. parallels = arange(-90.,90.,30.) if startlon==-180: meridians = arange(-180.,180.,60.) else: meridians = arange(0.,360.,60.) if verbose>1: print m.__doc__ xsize = rcParams['figure.figsize'][0] fig=figure(figsize=(xsize,m.aspect*xsize)) #ax = fig.add_axes([0.08,0.1,0.7,0.7],axisbg='white') ax = fig.add_axes([0.06,0.00,0.8,1.0],axisbg='white') # make a pcolor plot. #x, y = m(lons, lats) #p = m.pcolor(x,y,maskdat,shading='flat',cmap=cmap) #clim(*colorbounds) # axes units units are left, bottom, width, height #cax = axes([0.85, 0.1, 0.05, 0.7]) # colorbar axes for map w/ no graticule cax = axes([0.88, 0.1, 0.06, 0.81]) # colorbar axes for map w/ graticule axes(ax) # make the original axes current again ######### Plot symbol at station locations ################# #lines=open('file2.txt','r').readlines() #(lats,lons)=([],[]) #for line in lines: # (lat,lon)=line.strip().split(',') # lats.append(float(lat)) # lons.append(float(lon)) #for i in range(len(lons)): # plt.plot(lats,lons,'*') #plt.plot(lons,lats,'*') #data = csv2rec('file2.txt',delimiter=',') #plot(data[:,0],data[:,1],'o') #data = csv2rec('file2.txt',delimiter=' ',names=['lat','lon']) #plot(data['lat'],data['lon'],'o') data = np.loadtxt('file2.txt') plot(data[:,0],data[:,1],'o') xpt,ypt = m(-75.0,43.0) text(xpt,ypt,'*') # draw coastlines and political boundaries. m.drawcoastlines() m.drawcountries() m.drawstates() # draw parallels and meridians. # label on left, right and bottom of map. m.drawparallels(parallels,labels=[1,0,0,0]) m.drawmeridians(meridians,labels=[1,1,0,1]) #if plotfile: # savefig(plotfile, dpi=72, facecolor='w', bbox_inches='tight', edgecolor='w', orientation='portrait') #else: # show() #plt.savefig('map.png') plt.savefig('map.eps') # comment show to mass produce --- On Tue, 4/19/11, G Jones <gle...@gm...> wrote: From: G Jones <gle...@gm...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: "Ian Bell" <ib...@pu...>, Mat...@li... Date: Tuesday, April 19, 2011, 8:12 PM No need for a header, but I guess my example was a little too simple. You could do: data = csv2rec(filename,delimiter=' ',names=['lat','lon']) plot(data['lat'],data['lon'],'o') or you could do data = np.loadtxt(filename) plot(data[:,0],data[:,1],'o') In general, I strongly recommend developing with ipython --pylab. That way all the documentation is at your fingertips using the ? and ?? notation. -----Inline Attachment Follows----- ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev -----Inline Attachment Follows----- _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users
The first example produced no plotted symbols but no errors on execution. The second example produced this: Plotting, please wait...maybe more than 10 seconds Traceback (most recent call last): File "testNew.py", line 137, in <module> data = np.loadtxt('file2.txt') File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 489, in loadtxt X.append(tuple([conv(val) for (conv, val) in zip(converters, vals)])) ValueError: invalid literal for float(): 39.4670, Grrrr...... My code follows. I believe this is standard python and matplotlib. Should produce a map of Northeast US. Perhaps someone could get this working with a few example points: 39.4670, -76.1670 46.4000, -74.7670 45.3830, -75.7170 43.6170, -79.3830 45.5170, -73.4170 45.6170, -74.4170 43.8330, -77.1500 43.9500, -78.1670 43.2500, -79.2170 43.8330, -66.0830 #!/usr/bin/env python # v0.5 19 June 2010 # General purpose plotter of 2-D gridded data from NetCDF files, # plotted with map boundaries. # NetCDF file should have data in either 2-D, 3-D or 4-D arrays. # Works with the netCDF files in the tutorial, and also the # files available for download at: # http://www.cdc.noaa.gov/cdc/data.ncep.reanalysis.html # Adapted from the basemap example plotmap_pcolor.py, # Some of the variable names from that example are retained. # # Uses basemap's pcolor function. Pcolor accepts arrays # of the longitude and latitude points of the vertices on the pixels, # as well as an array with the numerical value in the pixel. verbose=0 #verbose=2 says a bit more import sys,getopt from mpl_toolkits.basemap import Basemap, shiftgrid, cm #from netCDF3 import Dataset as NetCDFFile from mpl_toolkits.basemap import NetCDFFile from pylab import * #from matplotlib.mlab import csv2rec alloptions, otherargs= getopt.getopt(sys.argv[1:],'ro:p:X:Y:v:t:l:u:n:') # note the : after o and p proj='lam' #plotfile=None #plotfile='testmap2.png' usejetrev=False colorbounds=[None,None] extratext="" xvar=None yvar=None thevar=None therec=None thelev=None cbot=None ctop=None startlon=-180 #default assumption for starting longitude for theopt,thearg in alloptions: print theopt,thearg if theopt=='-o': # -o needs filename after it, which is now thearg plotfile=thearg elif theopt=='-p': proj=thearg elif theopt=='-X': xvar=thearg elif theopt=='-Y': yvar=thearg elif theopt=='-v': thevar=thearg elif theopt=='-t': thetitle=thearg elif theopt=='-l': cbot=thearg elif theopt=='-u': ctop=thearg elif theopt=='-n': therec=thearg elif theopt=='-m': thelev=thearg elif theopt=='-r': usejetrev=True else: #something went wrong print "hmm, what are these??? ", theopt, thearg sys.exit() print "\nPlotting, please wait...maybe more than 10 seconds" if proj=='lam': #Lambert Conformal m = Basemap(llcrnrlon=-80.6,llcrnrlat=38.4,urcrnrlon=-66.0,urcrnrlat=47.7,\ resolution='l',area_thresh=1000.,projection='lcc',\ lat_1=65.,lon_0=-73.3) xtxt=200000. #offset for text ytxt=200000. parallels = arange(38.,48.,4.) meridians = arange(-80.,-68.,4.) else: #cylindrical is default # m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\ # resolution='c',area_thresh=10000.,projection='cyl') m = Basemap(llcrnrlon=startlon,llcrnrlat=-90,urcrnrlon=startlon+360.,urcrnrlat=90.,\ resolution='c',area_thresh=10000.,projection='cyl') xtxt=1. ytxt=0. parallels = arange(-90.,90.,30.) if startlon==-180: meridians = arange(-180.,180.,60.) else: meridians = arange(0.,360.,60.) if verbose>1: print m.__doc__ xsize = rcParams['figure.figsize'][0] fig=figure(figsize=(xsize,m.aspect*xsize)) #ax = fig.add_axes([0.08,0.1,0.7,0.7],axisbg='white') ax = fig.add_axes([0.06,0.00,0.8,1.0],axisbg='white') # make a pcolor plot. #x, y = m(lons, lats) #p = m.pcolor(x,y,maskdat,shading='flat',cmap=cmap) #clim(*colorbounds) # axes units units are left, bottom, width, height #cax = axes([0.85, 0.1, 0.05, 0.7]) # colorbar axes for map w/ no graticule cax = axes([0.88, 0.1, 0.06, 0.81]) # colorbar axes for map w/ graticule axes(ax) # make the original axes current again ######### Plot symbol at station locations ################# #lines=open('file2.txt','r').readlines() #(lats,lons)=([],[]) #for line in lines: # (lat,lon)=line.strip().split(',') # lats.append(float(lat)) # lons.append(float(lon)) #for i in range(len(lons)): # plt.plot(lats,lons,'*') #plt.plot(lons,lats,'*') #data = csv2rec('file2.txt',delimiter=',') #plot(data[:,0],data[:,1],'o') #data = csv2rec('file2.txt',delimiter=' ',names=['lat','lon']) #plot(data['lat'],data['lon'],'o') data = np.loadtxt('file2.txt') plot(data[:,0],data[:,1],'o') xpt,ypt = m(-75.0,43.0) text(xpt,ypt,'*') # draw coastlines and political boundaries. m.drawcoastlines() m.drawcountries() m.drawstates() # draw parallels and meridians. # label on left, right and bottom of map. m.drawparallels(parallels,labels=[1,0,0,0]) m.drawmeridians(meridians,labels=[1,1,0,1]) #if plotfile: # savefig(plotfile, dpi=72, facecolor='w', bbox_inches='tight', edgecolor='w', orientation='portrait') #else: # show() #plt.savefig('map.png') plt.savefig('map.eps') # comment show to mass produce --- On Tue, 4/19/11, G Jones <gle...@gm...> wrote: From: G Jones <gle...@gm...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: "Ian Bell" <ib...@pu...>, Mat...@li... Date: Tuesday, April 19, 2011, 8:12 PM No need for a header, but I guess my example was a little too simple. You could do: data = csv2rec(filename,delimiter=' ',names=['lat','lon']) plot(data['lat'],data['lon'],'o') or you could do data = np.loadtxt(filename) plot(data[:,0],data[:,1],'o') In general, I strongly recommend developing with ipython --pylab. That way all the documentation is at your fingertips using the ? and ?? notation.
No need for a header, but I guess my example was a little too simple. You could do: data = csv2rec(filename,delimiter=' ',names=['lat','lon']) plot(data['lat'],data['lon'],'o') or you could do data = np.loadtxt(filename) plot(data[:,0],data[:,1],'o') In general, I strongly recommend developing with ipython --pylab. That way all the documentation is at your fingertips using the ? and ?? notation. On Tue, Apr 19, 2011 at 5:03 PM, Michael Rawlins <raw...@ya...>wrote: > > Do I need to add something to the header(?) at top of file to use csv2rec? > > > import sys,getopt > > from mpl_toolkits.basemap import Basemap, shiftgrid, cm > from mpl_toolkits.basemap import NetCDFFile > from pylab import * > > > > > --- On *Tue, 4/19/11, Ian Bell <ib...@pu...>* wrote: > > > From: Ian Bell <ib...@pu...> > Subject: Re: [Matplotlib-users] plotting points/locations from data file > To: "G Jones" <gle...@gm...> > Cc: "Michael Rawlins" <raw...@ya...>, > Mat...@li... > Date: Tuesday, April 19, 2011, 7:35 PM > > > Have to say I whole-heartedly agree with Glenn. One problem I have run > into is a funky file headers where I want to skip lines 1,2,3, and 4, but > line 3 is my real header line which doesn't work so well with either of the > below solutions. I had to write my own wrapper to deal with these weird > types of files. > > Ian > > ---- > Ian Bell > Graduate Research Assistant > Herrick Labs > Purdue University > email: ib...@pu... <http://mc/compose?to=ib...@pu...> > cell: (607)227-7626 > > > On Tue, Apr 19, 2011 at 7:32 PM, G Jones <gle...@gm...<http://mc/compose?to=gle...@gm...> > > wrote: > > You may find it easier to use mlab.csv2rec or numpy.loadtxt. > > e.g. > > data = csv2rec(filename,delimiter=' ') > plot(data[:,0],data[:,1],'o') > > > > On Tue, Apr 19, 2011 at 4:26 PM, Michael Rawlins <raw...@ya...<http://mc/compose?to=raw...@ya...> > > wrote: > > > Sorry I should have mentioned that longitudes are negative; there is a '-' > before each longitude, like so: > > 39.4670 -76.1670 > 46.4000 -74.7670 > 45.3830 -75.7170 > 43.6170 -79.3830 > 45.5170 -73.4170 > > > Also the plt.text line you sent had lon[i] rather than lons[i]. I > corrected that and changed my longitudes to not have the '-' sign and the > code ran without error. Could the '-' be causing a problem? I need to input > the lat, lon as in the file as shown above. > > Mike > > > --- On *Tue, 4/19/11, Ian Bell <ib...@pu...<http://mc/compose?to=ib...@pu...> > >* wrote: > > > From: Ian Bell <ib...@pu... <http://mc/compose?to=ib...@pu...>> > Subject: Re: [Matplotlib-users] plotting points/locations from data file > To: "Michael Rawlins" <raw...@ya...<http://mc/compose?to=raw...@ya...> > > > Cc: Mat...@li...<http://mc/compose?to=Mat...@li...> > Date: Tuesday, April 19, 2011, 7:22 PM > > > If you want to plot a given marker at the point, for instance a circle, > replace the last line of my code plt.text...... with > > plt.plot(lats,lons,'o') > > for a circle, or > > plt.plot(lats,lons,'s') > > for a square. Refer to Plot<http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.plot>for more information on the markers you can use. You are getting the error > because you have a delimiter different than a single space, so it isn't > splitting the line. Replace ' ' in the split command with your whitespace > delimiter. Is it a tab? Then you want '\t' . > > Good luck, > Ian > > ---- > Ian Bell > Graduate Research Assistant > Herrick Labs > Purdue University > email: ib...@pu... <http://mc/compose?to=ib...@pu...> > cell: (607)227-7626 > > > On Tue, Apr 19, 2011 at 7:14 PM, Michael Rawlins <raw...@ya...<http://mc/compose?to=raw...@ya...> > > wrote: > > > Yes, there is whitespace between each lat and lon on each line. But, > actually, I'd simply like to plot a dot at each location. The '1' was there > in my example because I do not yet know how to plot a particular symbol. > Here is what I got when I tried the code you just suggested. > > Traceback (most recent call last): > File "test.py", line 319, in <module> > > (lat,lon)=line.strip().split(' ') > ValueError: too many values to unpack > > > There are 203 records in the data file. Line 319 of test.py is this: > > > (lat,lon)=line.strip().split(' ') > > > --- On *Tue, 4/19/11, Ian Bell <ib...@pu...<http://mc/compose?to=ib...@pu...> > >* wrote: > > > From: Ian Bell <ib...@pu... <http://mc/compose?to=ib...@pu...>> > Subject: Re: [Matplotlib-users] plotting points/locations from data file > To: "Michael Rawlins" <raw...@ya...<http://mc/compose?to=raw...@ya...> > > > Cc: Mat...@li...<http://mc/compose?to=Mat...@li...> > Date: Tuesday, April 19, 2011, 6:52 PM > > > To clarify, you are trying to read in a set of (lat,lon) points in a file > that is space delimited, store the data, and then put a text marker at each > point, with each point numbered in order? The critical part is that you > want to use a list (or numpy array) instead of a dictionary. Something like > this ought to do (don't have MPL on this computer though - pretty sure this > should work): > > lines=open('file.txt','r').readlines() > (lats,lons)=([],[]) > for line in lines: > (lat,lon)=line.strip().split(' ') > lats.append(float(lat)) > lons.append(float(lon)) > > for i in range(len(lons)): > plt.text(lats[i],lon[i],str(i+1),ha='center',va='center',color='white') > > I'm sure there are a bunch of more compact ways to do this, but this should > work. > > Ian > ---- > Ian Bell > Graduate Research Assistant > Herrick Labs > Purdue University > email: ib...@pu... <http://mc/compose?to=ib...@pu...> > cell: (607)227-7626 > > > On Tue, Apr 19, 2011 at 4:09 PM, Michael Rawlins <raw...@ya...<http://mc/compose?to=raw...@ya...> > > wrote: > > > I'm trying to plot a series of points/locations on a map. I'm reading the > latitudes and longitudes from a file, with each lat, lon pair on each record > (line). Here is the code: > > def make_float(line): > lati, longi = line.split() > return float(lati), float(longi) > > my_dict = {} > with open("file.txt") as f: > for item in f: > lati,longi = make_float(item) > my_dict[lati] = longi > > xpt,ypt = m(-76.1670,39.4670 ) > plt.text(xpt,ypt,'1',color='white') > > #print my_dict > > The matplotlib code which I've previously used to plot a single point on > the map is below, with longitude and latitude in ( ): > > xpt,ypt = m(-70.758392,42.960445) > plt.text(xpt,ypt,'1',color='white') > > When replacing (-70.758392,42.960445) with (longi,lati), the code plots > only a single '1' at the location of just the last coordinate pair in the > file. So now I only need to plot them all. Does the code I've implemented > have an implicit loop to it? > > Mike > > > > > ------------------------------------------------------------------------------ > Benefiting from Server Virtualization: Beyond Initial Workload > Consolidation -- Increasing the use of server virtualization is a top > priority.Virtualization can reduce costs, simplify management, and improve > application availability and disaster protection. Learn more about boosting > the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li...<http://mc/compose?to=Mat...@li...> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > > ------------------------------------------------------------------------------ > Benefiting from Server Virtualization: Beyond Initial Workload > Consolidation -- Increasing the use of server virtualization is a top > priority.Virtualization can reduce costs, simplify management, and improve > application availability and disaster protection. Learn more about boosting > the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li...<http://mc/compose?to=Mat...@li...> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > >
Do I need to add something to the header(?) at top of file to use csv2rec? import sys,getopt from mpl_toolkits.basemap import Basemap, shiftgrid, cm from mpl_toolkits.basemap import NetCDFFile from pylab import * --- On Tue, 4/19/11, Ian Bell <ib...@pu...> wrote: From: Ian Bell <ib...@pu...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "G Jones" <gle...@gm...> Cc: "Michael Rawlins" <raw...@ya...>, Mat...@li... Date: Tuesday, April 19, 2011, 7:35 PM Have to say I whole-heartedly agree with Glenn. One problem I have run into is a funky file headers where I want to skip lines 1,2,3, and 4, but line 3 is my real header line which doesn't work so well with either of the below solutions. I had to write my own wrapper to deal with these weird types of files. Ian ---- Ian Bell Graduate Research Assistant Herrick Labs Purdue University email: ib...@pu... cell: (607)227-7626 On Tue, Apr 19, 2011 at 7:32 PM, G Jones <gle...@gm...> wrote: You may find it easier to use mlab.csv2rec or numpy.loadtxt. e.g. data = csv2rec(filename,delimiter=' ') plot(data[:,0],data[:,1],'o') On Tue, Apr 19, 2011 at 4:26 PM, Michael Rawlins <raw...@ya...> wrote: Sorry I should have mentioned that longitudes are negative; there is a '-' before each longitude, like so: 39.4670 -76.1670 46.4000 -74.7670 45.3830 -75.7170 43.6170 -79.3830 45.5170 -73.4170 Also the plt.text line you sent had lon[i] rather than lons[i]. I corrected that and changed my longitudes to not have the '-' sign and the code ran without error. Could the '-' be causing a problem? I need to input the lat, lon as in the file as shown above. Mike --- On Tue, 4/19/11, Ian Bell <ib...@pu...> wrote: From: Ian Bell <ib...@pu...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: Mat...@li... Date: Tuesday, April 19, 2011, 7:22 PM If you want to plot a given marker at the point, for instance a circle, replace the last line of my code plt.text...... with plt.plot(lats,lons,'o') for a circle, or plt.plot(lats,lons,'s') for a square. Refer to Plot for more information on the markers you can use. You are getting the error because you have a delimiter different than a single space, so it isn't splitting the line. Replace ' ' in the split command with your whitespace delimiter. Is it a tab? Then you want '\t' . Good luck, Ian ---- Ian Bell Graduate Research Assistant Herrick Labs Purdue University email: ib...@pu... cell: (607)227-7626 On Tue, Apr 19, 2011 at 7:14 PM, Michael Rawlins <raw...@ya...> wrote: Yes, there is whitespace between each lat and lon on each line. But, actually, I'd simply like to plot a dot at each location. The '1' was there in my example because I do not yet know how to plot a particular symbol. Here is what I got when I tried the code you just suggested. Traceback (most recent call last): File "test.py", line 319, in <module> (lat,lon)=line.strip().split(' ') ValueError: too many values to unpack There are 203 records in the data file. Line 319 of test.py is this: (lat,lon)=line.strip().split(' ') --- On Tue, 4/19/11, Ian Bell <ib...@pu...> wrote: From: Ian Bell <ib...@pu...> Subject: Re: [Matplotlib-users] plotting points/locations from data file To: "Michael Rawlins" <raw...@ya...> Cc: Mat...@li... Date: Tuesday, April 19, 2011, 6:52 PM To clarify, you are trying to read in a set of (lat,lon) points in a file that is space delimited, store the data, and then put a text marker at each point, with each point numbered in order? The critical part is that you want to use a list (or numpy array) instead of a dictionary. Something like this ought to do (don't have MPL on this computer though - pretty sure this should work): lines=open('file.txt','r').readlines() (lats,lons)=([],[]) for line in lines: (lat,lon)=line.strip().split(' ') lats.append(float(lat)) lons.append(float(lon)) for i in range(len(lons)): plt.text(lats[i],lon[i],str(i+1),ha='center',va='center',color='white') I'm sure there are a bunch of more compact ways to do this, but this should work. Ian ---- Ian Bell Graduate Research Assistant Herrick Labs Purdue University email: ib...@pu... cell: (607)227-7626 On Tue, Apr 19, 2011 at 4:09 PM, Michael Rawlins <raw...@ya...> wrote: I'm trying to plot a series of points/locations on a map. I'm reading the latitudes and longitudes from a file, with each lat, lon pair on each record (line). Here is the code: def make_float(line): lati, longi = line.split() return float(lati), float(longi) my_dict = {} with open("file.txt") as f: for item in f: lati,longi = make_float(item) my_dict[lati] = longi xpt,ypt = m(-76.1670,39.4670 ) plt.text(xpt,ypt,'1',color='white') #print my_dict The matplotlib code which I've previously used to plot a single point on the map is below, with longitude and latitude in ( ): xpt,ypt = m(-70.758392,42.960445) plt.text(xpt,ypt,'1',color='white') When replacing (-70.758392,42.960445) with (longi,lati), the code plots only a single '1' at the location of just the last coordinate pair in the file. So now I only need to plot them all. Does the code I've implemented have an implicit loop to it? Mike ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users