[matplotlib-devel] basemap domain changes on pyplot call

I did some more digging and I think I have a hypothesis
for what is happening.

There is only one main difference between a call to .drawstates() and
.readshapefiles() with respect to loading and plotting data.
.drawstates() loads only the line segments that coincide with the
defined map boundaries, while .readshapefiles() loads all of the data
in the shapefile. Therefore, the LineCollection that gets attached to
the axis contains data from outside the stated domain.

In addition, the basemap versions of the plotting functions have the
benefit of finishing their calls with a call to .set_axes_limits(),
which keeps the axes in check. However, a non-basemap version would
not call that automatically, thereby having its axes automatically
expanded to contain all of the data in the LineCollection.

I am not sure what exactly should be done about this. This is
certainly un-intuitive behavior, though. Maybe there could be a keyword
option in .readshapefile() to have only the data for the stated domain
loaded? That might solve the issue.

Thanks,

Ben Root

Ben: That’s why you should use the basemap methods where possible
(they handle these things for you). You could also turn autoscaling
off on your axes using

ax.set_autoscaleon(False)

and then they won’t automatically expand when you plot data outside
your map region. Or, you could just call the set_axes_limits() methods
before you draw the plot.

Clipping the polygons to the map projection region is non-trivial, and
I don’t think I want to add that to readshapefile.

-Jeff

···

Matplotlib-devel@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-devel

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

Jeffrey.S.Whitaker@…259…http://tinyurl.com/5telg

I did some more digging and I think I have a hypothesis
for what is happening.

There is only one main difference between a call to .drawstates() and
.readshapefiles() with respect to loading and plotting data.
.drawstates() loads only the line segments that coincide with the
defined map boundaries, while .readshapefiles() loads all of the data
in the shapefile. Therefore, the LineCollection that gets attached to
the axis contains data from outside the stated domain.

In addition, the basemap versions of the plotting functions have the
benefit of finishing their calls with a call to .set_axes_limits(),
which keeps the axes in check. However, a non-basemap version would
not call that automatically, thereby having its axes automatically
expanded to contain all of the data in the LineCollection.

I am not sure what exactly should be done about this. This is
certainly un-intuitive behavior, though. Maybe there could be a keyword
option in .readshapefile() to have only the data for the stated domain
loaded? That might solve the issue.

Thanks,

Ben Root

Ben: That’s why you should use the basemap methods where possible
(they handle these things for you).

Yeah, that wasn’t possible in my case. In addition, not all pyplot plotting functions are available (nor do I expect Basemap to have all of them available). Therefore, it often makes more sense for me to use the pyplot functions and just give Basemap the axes.

You could also turn autoscaling
off on your axes using

ax.set_autoscaleon(False)

and then they won’t automatically expand when you plot data outside
your map region. Or, you could just call the set_axes_limits() methods
before you draw the plot.

At the least, I think this advice should be thoroughly documented, especially in the docstring for readshapefile(). This behavior was quite perplexing to me and it took a while to figure out the cause. I am one of those people who will not leave well enough alone…

Clipping the polygons to the map projection region is non-trivial, and
I don’t think I want to add that to readshapefile.

Personally, I think there should be a family of .draw*() functions that behave like .drawstates(). One of those functions can be .drawshapefile(). Then there would be a family of .read*() functions that could be called either by the user or by the .draw*() functions. The .read*() function could have an option to perform a clip of the incoming data.

If you like to discuss this further, I would be more than happy to help out.

Ben Root

···

On Fri, May 21, 2010 at 5:16 PM, Jeff Whitaker <jswhit@…83…146…> wrote:

On 5/21/10 3:57 PM, Benjamin Root wrote:

Benjamin Root wrote:

On Fri, May 21, 2010 at 5:16 PM, Jeff Whitaker <jswhit@...146... Ben: That's why you should use the basemap methods where possible
    (they handle these things for you).

Yeah, that wasn't possible in my case. In addition, not all pyplot plotting functions are available (nor do I expect Basemap to have all of them available).

Though it would be nice to add more as we need them. I assume Jeff will take contributions.

I need to be able to draw a filled polygon from coordinates in memory, for instance, but didn't see a way to do this directly. If I get a chance, I will look into .drawshapefile(), and figure I can see how to do it from there.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Chris: If you have the map projection coordinates of the polygon, you can just use the pyplot commands or axes methods, and then use the Basemap set_axes_limits method to make sure the aspect ratio and axes limits get reset correctly.

-Jeff

···

On 5/24/10 10:24 AM, Christopher Barker wrote:

Benjamin Root wrote:
   

On Fri, May 21, 2010 at 5:16 PM, Jeff Whitaker<jswhit@...146...
     Ben: That's why you should use the basemap methods where possible
     (they handle these things for you).

Yeah, that wasn't possible in my case. In addition, not all pyplot
plotting functions are available (nor do I expect Basemap to have all of
them available).
     

Though it would be nice to add more as we need them. I assume Jeff will
take contributions.

I need to be able to draw a filled polygon from coordinates in memory,
for instance, but didn't see a way to do this directly. If I get a
chance, I will look into .drawshapefile(), and figure I can see how to
do it from there.

-Chris

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

`Ben: The shapefile stuff in Basemap certainly could use some
work. If you’d like to help, that would be great.

-Jeff

`

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

Jeffrey.S.Whitaker@…259…http://tinyurl.com/5telg

Jeff,
would it be possible to achieve this type of layering using multiple overlaid (sub) plots?
If so, how would I go about this?

do you know of any way I might be able to create a custom ‘hack’ into the imshow code (within the matplotlib core) ???

thanks again,
p.romero

···

Date: Mon, 24 May 2010 11:44:53 -0600
From: jswhit@…3119…
To: Chris.Barker@…259…; matplotlib-users@…504…et
Subject: Re: [Matplotlib-users] [matplotlib-devel] basemap domain changes on pyplot call

On 5/24/10 10:24 AM, Christopher Barker wrote:

Benjamin Root wrote:

On Fri, May 21, 2010 at 5:16 PM, Jeff Whitaker<jswhit@…146…
Ben: That’s why you should use the basemap methods where possible
(they handle these things for you).

Yeah, that wasn’t possible in my case. In addition, not all pyplot
plotting functions are available (nor do I expect Basemap to have all of
them available).

Though it would be nice to add more as we need them. I assume Jeff will
take contributions.

I need to be able to draw a filled polygon from coordinates in memory,
for instance, but didn’t see a way to do this directly. If I get a
chance, I will look into .drawshapefile(), and figure I can see how to
do it from there.

-Chris

Chris: If you have the map projection coordinates of the polygon, you
can just use the pyplot commands or axes methods, and then use the
Basemap set_axes_limits method to make sure the aspect ratio and axes
limits get reset correctly.

-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 : http://tinyurl.com/5telg



Matplotlib-users mailing list
Matplotlib-users@…1735…sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. Learn more.

hello,
please ignore my last response; I responded to the wrong mailing list message…

···

From: romero619@…32…
To: jswhit@…146…; chris.barker@…259…; matplotlib-users@…1753…forge.net
Date: Mon, 24 May 2010 13:10:23 -0500
Subject: Re: [Matplotlib-users] [matplotlib-devel] basemap domain changes on pyplot call

Jeff,
would it be possible to achieve this type of layering using multiple overlaid (sub) plots?
If so, how would I go about this?

Send

do you know of any way I might be able to create a custom ‘hack’ into the imshow code (within the matplotlib core) ???

thanks again,
p.romero

Date: Mon, 24 May 2010 11:44:53 -0600
From: jswhit@…146…
To: Chris.Barker@…259…; matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] [matplotlib-devel] basemap domain changes on pyplot call

On 5/24/10 10:24 AM, Christopher Barker wrote:

Benjamin Root wrote:

On Fri, May 21, 2010 at 5:16 PM, Jeff Whitaker<jswhit@…146…
Ben: That’s why you should use the basemap methods where possible
(they handle these things for you).

Yeah, that wasn’t possible in my case. In addition, not all pyplot
plotting functions are available (nor do I expect Basemap to have all of
them available).

Though it would be nice to add more as we need them. I assume Jeff will
take contributions.

I need to be able to draw a filled polygon from coordinates in memory,
for instance, but didn’t see a way to do this directly. If I get a
chance, I will look into .drawshapefile(), and figure I can see how to
do it from there.

-Chris

Chris: If you have the map projection coordinates of the polygon, you
can just use the pyplot commands or axes methods, and then use the
Basemap set_axes_limits method to make sure the aspect ratio and axes
limits get reset correctly.

-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 : http://tinyurl.com/5telg



Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. Learn more.


Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox. Learn more.

Jeff Whitaker wrote:

I need to be able to draw a filled polygon from coordinates in memory,
for instance, but didn't see a way to do this directly.

Chris: If you have the map projection coordinates of the polygon,

nope -- we've got lat-long

you can just use the pyplot commands or axes methods, and then use the Basemap set_axes_limits method to make sure the aspect ratio and axes limits get reset correctly.

I'll look into that too -- if I have time.

Thanks,
   -Chris

···

On 5/24/10 10:24 AM, Christopher Barker wrote:

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Chris,

If you have lat-long, you can call your basemap object to convert it to map coordinates. I forget if you have to call inverse=True or not. Off the top of my head it would be something like this (assuming ‘map’ is your Basemap object that has already been initialized):

x, y = map(45.0, -104.5, inverse=True)

You can find much more accurate information and examples from doing a help(map).

Ben Root

···

On Mon, May 24, 2010 at 6:12 PM, Christopher Barker <Chris.Barker@…259…> wrote:

Jeff Whitaker wrote:

On 5/24/10 10:24 AM, Christopher Barker wrote:

I need to be able to draw a filled polygon from coordinates in memory,

for instance, but didn’t see a way to do this directly.

Chris: If you have the map projection coordinates of the polygon,

nope – we’ve got lat-long

you

can just use the pyplot commands or axes methods, and then use the

Basemap set_axes_limits method to make sure the aspect ratio and axes

limits get reset correctly.

I’ll look into that too – if I have time.

Thanks,
-Chris

Christopher Barker, Ph.D.

Oceanographer

Emergency Response Division

NOAA/NOS/OR&R (206) 526-6959 voice

7600 Sand Point Way NE (206) 526-6329 fax

Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@…259…



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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