How do I make a legend for Line2D objects in Basemap, colored using a colormap?

Zane Selvans <zane@...83...> writes:

I'm plotting a bunch of lines on a map. They're being colored
according to the value of an attribute associated with the objects
they represent, using a colormap. However, I also need to create a
colorbar to act as a legend, describing what the colors of the lines
means, in terms of values associated with that attribute.

What's the easiest way to do that?

I've found the matplotlib.colorbar.ColorbarBase class... and have been able to
use matplotlib.colorbar.make_axes() to create a somewhat acceptable set of axes
into which I can put a colorbar constructed from the same colormap that I'm
using to color the lines I'm plotting. However, I can't seem to get the tics
and axes on the colorbar to correspond to the values associated with the colors
- they only ever go from 0-1. I want them to go from, for instance, 0-180
(degrees) in 20 or 30 degree intervals. It seemed like setting the keyword
arguments in ColorbarBase(boundaries=[0,180]) or values=linspace(0,180,10) or
something like that ought to have done the right thing... but no, and I don't
see any documentation on how these keywords are supposed to be used, in the
docstring or elsewhere... anyone know how they work?

Zane Selvans wrote:

Zane Selvans <zane@...83...> writes:

I'm plotting a bunch of lines on a map. They're being colored
according to the value of an attribute associated with the objects
they represent, using a colormap. However, I also need to create a
colorbar to act as a legend, describing what the colors of the lines
means, in terms of values associated with that attribute.

What's the easiest way to do that?

I've found the matplotlib.colorbar.ColorbarBase class... and have been able to
use matplotlib.colorbar.make_axes() to create a somewhat acceptable set of axes
into which I can put a colorbar constructed from the same colormap that I'm
using to color the lines I'm plotting. However, I can't seem to get the tics
and axes on the colorbar to correspond to the values associated with the colors
- they only ever go from 0-1. I want them to go from, for instance, 0-180
(degrees) in 20 or 30 degree intervals. It seemed like setting the keyword
arguments in ColorbarBase(boundaries=[0,180]) or values=linspace(0,180,10) or
something like that ought to have done the right thing... but no, and I don't
see any documentation on how these keywords are supposed to be used, in the
docstring or elsewhere... anyone know how they work?

You need to pass an instance of a matplotlib.colors.Normalize to the
constructure to ColorbarBase, as in:

cbar = ColorbarBase(norm=Normalize(0, 180))

As far as colormapping lines, you can do this using a LineCollection object.

Hope this helps,

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Zane Selvans wrote:

Zane Selvans <zane@...83...> writes:

I also need to create a
colorbar to act as a legend, describing what the colors of the lines
means, in terms of values associated with that attribute.

I've found the matplotlib.colorbar.ColorbarBase class...
I want them to go from, for instance, 0-180
(degrees) in 20 or 30 degree intervals. It seemed like setting the keyword
arguments in ColorbarBase(boundaries=[0,180]) or values=linspace(0,180,10) or
something like that ought to have done the right thing... but no, and I don't
see any documentation on how these keywords are supposed to be used, in the
docstring or elsewhere... anyone know how they work?

You need to pass an instance of a matplotlib.colors.Normalize to the
constructure to ColorbarBase, as in:

cbar = ColorbarBase(norm=Normalize(0, 180))

Ahhh. There we go.

As far as colormapping lines, you can do this using a LineCollection object.

Hmm. I'll have a look at these. Jeff Whitaker suggested them for something else too. I too often feel like I'm just hacking my way around in Matplotlib, without understanding how it is actually "supposed" to be used (i.e. how it was designed to work). Is there an architectural overview floating around somewhere that I'm not aware of?

Thanks for the help!
Zane

···

On Oct 9, 2008, at 7:08 AM, Ryan May wrote:

--
Zane Selvans
Amateur Earthling
zane@...1923...
303/815-6866

PGP Key: 55E0815F

Check out http://matplotlib.sourceforge.net/doc/html/users/artists.html
and other docs at
http://matplotlib.sourceforge.net/doc/html/index.html

···

On Thu, Oct 9, 2008 at 2:40 PM, Zane Selvans <zane@...1923...> wrote:

Hmm. I'll have a look at these. Jeff Whitaker suggested them for
something else too. I too often feel like I'm just hacking my way
around in Matplotlib, without understanding how it is actually
"supposed" to be used (i.e. how it was designed to work). Is there an
architectural overview floating around somewhere that I'm not aware of?

John Hunter wrote:

···

On Thu, Oct 9, 2008 at 2:40 PM, Zane Selvans <zane@...1923...> wrote:

Hmm. I'll have a look at these. Jeff Whitaker suggested them for
something else too. I too often feel like I'm just hacking my way
around in Matplotlib, without understanding how it is actually
"supposed" to be used (i.e. how it was designed to work). Is there an
architectural overview floating around somewhere that I'm not aware of?
    
Check out http://matplotlib.sourceforge.net/doc/html/users/artists.html
and other docs at
http://matplotlib.sourceforge.net/doc/html/index.html
  
and basemap specific docs are at

http://matplotlib.sourceforge.net/basemap/doc/html

-Jeff

--
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

Zane Selvans wrote:

Zane Selvans <zane@...83...> writes:

I'm plotting a bunch of lines on a map. They're being colored according to the value of an attribute associated with the objects they represent, using a colormap. However, I also need to create a colorbar to act as a legend, describing what the colors of the lines means, in terms of values associated with that attribute.

What's the easiest way to do that?

I've found the matplotlib.colorbar.ColorbarBase class... and have been able to
use matplotlib.colorbar.make_axes() to create a somewhat acceptable set of axes
into which I can put a colorbar constructed from the same colormap that I'm
using to color the lines I'm plotting. However, I can't seem to get the tics
and axes on the colorbar to correspond to the values associated with the colors
- they only ever go from 0-1. I want them to go from, for instance, 0-180
(degrees) in 20 or 30 degree intervals. It seemed like setting the keyword
arguments in ColorbarBase(boundaries=[0,180]) or values=linspace(0,180,10) or
something like that ought to have done the right thing... but no, and I don't
see any documentation on how these keywords are supposed to be used, in the
docstring or elsewhere... anyone know how they work?

You probably want to use the ColorbarBase.add_lines() method; you can get an example of its use for line contours in the Colorbar class, and an example of the result is in examples/pylab_examples/contour_demo.py.

Eric

That’s just what I was looking for.

However, unfortunately there appears to be some problem with the generation of the figures which are supposed to be embedded within that documentation - they’re all appearing as nothing but blank white spaces, both in Firefox 3.0.3 on OS X 10.5.5, and when I download the files and view them with other programs. Do other people see this problem?

Thanks again,

Zane

···

On Oct 9, 2008, at 12:55 PM, John Hunter wrote:

On Thu, Oct 9, 2008 at 2:40 PM, Zane Selvans <zane@…1923…> wrote:

I too often feel like I’m just hacking my way
around in Matplotlib, without understanding how it is actually
“supposed” to be used (i.e. how it was designed to work). Is there an
architectural overview floating around somewhere that I’m not aware of?

Check out http://matplotlib.sourceforge.net/doc/html/users/artists.html

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

Zane Selvans wrote:

I too often feel like I'm just hacking my way
around in Matplotlib, without understanding how it is actually
"supposed" to be used (i.e. how it was designed to work). Is there an
architectural overview floating around somewhere that I'm not aware of?

Check out http://matplotlib.sourceforge.net/doc/html/users/artists.html

That's just what I was looking for.

However, unfortunately there appears to be some problem with the generation of the figures which are supposed to be embedded within that documentation - they're all appearing as nothing but blank white spaces, both in Firefox 3.0.3 on OS X 10.5.5, and when I download the files and view them with other programs. Do other people see this problem?

Yes, something is broken. I don't know how to fix it, though.

Eric

···

On Oct 9, 2008, at 12:55 PM, John Hunter wrote:

On Thu, Oct 9, 2008 at 2:40 PM, Zane Selvans <zane@...1923... >> <mailto:zane@…1923…>> wrote:

Thanks again,
Zane

--
Zane Selvans
Amateur Earthling
zane@...1923... <mailto:zane@…1923…>
303/815-6866
http://zaneselvans.org
PGP Key: 55E0815F

------------------------------------------------------------------------

-------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

However, unfortunately there appears to be some problem with the
generation of the figures which are supposed to be embedded within that
documentation - they're all appearing as nothing but blank white spaces,
both in Firefox 3.0.3 on OS X 10.5.5, and when I download the files and view
them with other programs. Do other people see this problem?

Yes, something is broken. I don't know how to fix it, though.

It looks like either the rsync screwed up or sf is throttling us or
both. I got this message in my cron job

  ssh: connect to host matplotlib.sf.net port 22: Connection refused
  rsync: connection unexpectedly closed (0 bytes received so far) [sender]
  rsync error: unexplained error (code 255) at io.c(453) [sender=2.6.9]
  ssh: connect to host matplotlib.sf.net port 22: Connection refused
  lost connection

when I check the images in the
http://matplotlib.sourceforge.net/doc/html/pyplots/ directory, they
are there but are smaller in filesize than they are in the directory
on the build machine, suggesting they were truncated in the transfer.
When I try and log into the sf shell server

  > ssh -l jdh2358 shell.sf.net

it hangs.

Normally they send me an email when I am over file size quota, so I
would be surprised if they simply throttled us w/o a warning, but I
will file a ticket with the sf folks and see if they can help.

JDH

···

On Mon, Oct 13, 2008 at 6:56 PM, Eric Firing <efiring@...202...> wrote:

I saw this blank image problem a couple of weeks ago, and I was seeing it in my local doc builds as well.

It appeared then that this change broke inline plots:

"""
r6089 | jdh2358 | 2008-09-13 10:28:09 -0400 (Sat, 13 Sep 2008) | 1 line

replaced ipython run magic with code.InteractiveConsole.runsource
"""

because InteractiveConsole injects a number of things in __builtin__ that interfere with recent SVN versions of Sphinx.

"""
r6137 | mdboom | 2008-09-30 16:07:54 -0400 (Tue, 30 Sep 2008) | 3 lines

[ 2138392 ] API doc for add_subplot()
Also fixing numerous problems with the documentation build. It seems that the change in plot_directive.py to use the "code" module to run scripts interferes with i18n in Sphinx (due to the overloading of '_' as a symbol). Changed to use the fewer-moving-parts imp.load_module() instead.
"""

I changed this in SVN to just use imp.load_module instead, and this resolved the problem locally. I had expected the doc buildbot to pick it up and run with it, but I never followed up to see if it ever did. It's possible that this SF quota/login etc. problem has been blocking the updates all this time. So it's not necessarily that the files are transferring incorrectly, merely that they haven't been transferring at all since Sept 30 or before.

If my change doesn't fix the image problem for you or the buildbot, let me know and I can revert it.

Mike

John Hunter wrote:

···

On Mon, Oct 13, 2008 at 6:56 PM, Eric Firing <efiring@...202...> wrote:

However, unfortunately there appears to be some problem with the
generation of the figures which are supposed to be embedded within that
documentation - they're all appearing as nothing but blank white spaces,
both in Firefox 3.0.3 on OS X 10.5.5, and when I download the files and view
them with other programs. Do other people see this problem?
      

Yes, something is broken. I don't know how to fix it, though.
    
It looks like either the rsync screwed up or sf is throttling us or
both. I got this message in my cron job

  ssh: connect to host matplotlib.sf.net port 22: Connection refused
  rsync: connection unexpectedly closed (0 bytes received so far) [sender]
  rsync error: unexplained error (code 255) at io.c(453) [sender=2.6.9]
  ssh: connect to host matplotlib.sf.net port 22: Connection refused
  lost connection

when I check the images in the
http://matplotlib.sourceforge.net/doc/html/pyplots/ directory, they
are there but are smaller in filesize than they are in the directory
on the build machine, suggesting they were truncated in the transfer.
When I try and log into the sf shell server

  > ssh -l jdh2358 shell.sf.net

it hangs.

Normally they send me an email when I am over file size quota, so I
would be surprised if they simply throttled us w/o a warning, but I
will file a ticket with the sf folks and see if they can help.

JDH

-------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Just checked my cron emails again and indeed, the last successful
update was in mid September. I'll need to keep a closer eye on these.

Indeed, sourceforge revamped their shell services and I missed the
email. Details are here

  http://sourceforge.net/community/forum/topic.php?id=3471&page&replies=2

Short answer: there is no longer any ssh shell access but sftp and
rsync over ssh are supported. The new server is web.sf.net. I
updated my makefile and synced the docs, so
http://matplotlib.sourceforge.net/doc/html/ is live again

JDH
JDH

···

On Tue, Oct 14, 2008 at 7:35 AM, Michael Droettboom <mdroe@...86...> wrote:

I saw this blank image problem a couple of weeks ago, and I was seeing it in
my local doc builds as well.

It appeared then that this change broke inline plots:

"""
r6089 | jdh2358 | 2008-09-13 10:28:09 -0400 (Sat, 13 Sep 2008) | 1 line

replaced ipython run magic with code.InteractiveConsole.runsource
"""

because InteractiveConsole injects a number of things in __builtin__ that
interfere with recent SVN versions of Sphinx.

"""
r6137 | mdboom | 2008-09-30 16:07:54 -0400 (Tue, 30 Sep 2008) | 3 lines

[ 2138392 ] API doc for add_subplot()
Also fixing numerous problems with the documentation build. It seems that
the change in plot_directive.py to use the "code" module to run scripts
interferes with i18n in Sphinx (due to the overloading of '_' as a symbol).
Changed to use the fewer-moving-parts imp.load_module() instead.
"""

I changed this in SVN to just use imp.load_module instead, and this resolved
the problem locally. I had expected the doc buildbot to pick it up and run
with it, but I never followed up to see if it ever did. It's possible that
this SF quota/login etc. problem has been blocking the updates all this
time. So it's not necessarily that the files are transferring incorrectly,
merely that they haven't been transferring at all since Sept 30 or before.