Plotting multi-colored lines atop basemap instances

I am attempting to plot a line atop a basemap instance called “m”. I can do this without a problem with:

plot = m.plot(lon,lat,‘r-’) #lon and lat are lists

However, I’d like to color the line based on a third list called “intensity.” For instance, if the value of intensity between two points is 0-35 make it green, 35-70 make it yellow, etc.

I have studied this example: http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine but I cannot get a collection added to the figure without errors.

Has anyone done similar?

Thanks!

···

Bruce W. Ford
Clear Science, Inc.

Bruce: Can you show us how you are doing it (and what the error message is)? You should just be able to add the line collection to the axes instance that the Basemap instance is drawing on.

-J

···

On 2/9/11 7:51 AM, Bruce Ford wrote:

I am attempting to plot a line atop a basemap instance called "m". I can do this without a problem with:

plot = m.plot(lon,lat,'r-') #lon and lat are lists

However, I'd like to color the line based on a third list called "intensity." For instance, if the value of intensity between two points is 0-35 make it green, 35-70 make it yellow, etc.

I have studied this example: http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine but I cannot get a collection added to the figure without errors.

Has anyone done similar?

Thanks!

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

Bruce,

···

From: bruce@…2905…
Date: Wed, 9 Feb 2011 09:51:06 -0500
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Plotting multi-colored lines atop basemap instances

I am attempting to plot a line atop a basemap instance called “m”. I can do this without a problem with:

plot = m.plot(lon,lat,‘r-’) #lon and lat are lists

However, I’d like to color the line based on a third list called “intensity.” For instance, if the value of intensity between two points is 0-35 make it green, 35-70 make it yellow, etc.

I have studied this example: http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine but I cannot get a collection added to the figure without errors.

You can always use ‘regular’ pyplot methods on your plot :

fig = plt.figure()

ax = fig.subplot(111)

m = Basemap(etc…)

convert your lon/lat to X,Y in the basemap projection:

X,Y = m(lon,lat)

then plot your line as if you were using only pyplot :

plt.plot(X,Y)

This way, you can add the collection as

ax.add_collection(somecollection)

HTH,

Thomas

I brute-forced this another way by dealing the arrays I had created.

Thanks for the suggestions!

···

Bruce W. Ford
Clear Science, Inc.

On Wed, Feb 9, 2011 at 10:30 AM, Jeff Whitaker <jswhit@…83…146…> wrote:

On 2/9/11 7:51 AM, Bruce Ford wrote:

I am attempting to plot a line atop a basemap instance called “m”. I

can do this without a problem with:

plot = m.plot(lon,lat,‘r-’) #lon and lat are lists

However, I’d like to color the line based on a third list called

“intensity.” For instance, if the value of intensity between two

points is 0-35 make it green, 35-70 make it yellow, etc.

I have studied this example:

http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine but I cannot

get a collection added to the figure without errors.

Has anyone done similar?

Thanks!

Bruce: Can you show us how you are doing it (and what the error message

is)? You should just be able to add the line collection to the axes

instance that the Basemap instance is drawing on.

-J

Jeffrey S. Whitaker Phone : (303)497-6313

Meteorologist FAX : (303)497-6449

NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@…259…

325 Broadway Office : Skaggs Research Cntr 1D-113

Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg


The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:

Pinpoint memory and threading errors before they happen.

Find and fix more than 250 security defects in the development cycle.

Locate bottlenecks in serial and parallel code that limit performance.

http://p.sf.net/sfu/intel-dev2devfeb


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users