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...@purdue.edu
cell: (607)227-7626


On Tue, Apr 19, 2011 at 7:14 PM, Michael Rawlins <rawlin...@yahoo.com>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...@purdue.edu>* wrote:
>
>
> From: Ian Bell <ib...@purdue.edu>
> Subject: Re: [Matplotlib-users] plotting points/locations from data file
> To: "Michael Rawlins" <rawlin...@yahoo.com>
> Cc: Matplotlib-users@lists.sourceforge.net
> 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...@purdue.edu <http://mc/compose?to=ib...@purdue.edu>
> cell: (607)227-7626
>
>
> On Tue, Apr 19, 2011 at 4:09 PM, Michael Rawlins 
> <rawlin...@yahoo.com<http://mc/compose?to=rawlin...@yahoo.com>
> > 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
> Matplotlib-users@lists.sourceforge.net<http://mc/compose?to=Matplotlib-users@lists.sourceforge.net>
> 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to