Plotting maps with matplotlib-basemap very slow

I would like to draw very, very simple maps of only europe in matplotlib /
basemap, which takes very much time (around 10 seconds!). This is just
unreal!? Setting of resolution is only "l" (low).
I need to plot hundreds of those maps every few hours. This would be
impossible!!? :frowning:

Here is the very simple code:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

m = Basemap(projection='stere',lon_0=5,lat_0=90.0,rsphere=6371200.,\
       
llcrnrlon=-25.0,urcrnrlon=72.0,llcrnrlat=26.0,urcrnrlat=65.0,resolution='l')

m.drawcoastlines(linewidth=0.2)
m.drawcountries(linewidth=0.2)
plt.savefig('/var/www/map.png')

Hope you can help! :frowning:

Regards

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi,

Have you considered reading from a suitably low-resolution shapefile
instead? I suppose overlays or colors change per generation but not
the geographical area.

Cheers,

Christian

···

On Sat, Jan 24, 2015 at 4:11 PM, Sappy85 <robert.wittkopf@...380...> wrote:

I would like to draw very, very simple maps of only europe in matplotlib /
basemap, which takes very much time (around 10 seconds!). This is just
unreal!? Setting of resolution is only "l" (low).
I need to plot hundreds of those maps every few hours. This would be
impossible!!? :frowning:

Here is the very simple code:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

m = Basemap(projection='stere',lon_0=5,lat_0=90.0,rsphere=6371200.,\

llcrnrlon=-25.0,urcrnrlon=72.0,llcrnrlat=26.0,urcrnrlat=65.0,resolution='l')

m.drawcoastlines(linewidth=0.2)
m.drawcountries(linewidth=0.2)
plt.savefig('/var/www/map.png')

Hope you can help! :frowning:

Regards

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi, yes that helps a lot, reading in the boundaries from a shapefile.

But does anybody know, how avoid the "double inner borders"? Coastlines seem
to have a thinner border. Borders between two countries be drawn twice.

<http://matplotlib.1069221.n5.nabble.com/file/n44757/map.png>

Regards

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755p44757.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

10 seconds? That doesn’t seem right. Are you running the process as an apache user or something without a home directory? I suspect that the font cache is not being created, and so it is having to build the font listing every time it starts up.

Ben Root

···

On Jan 24, 2015 1:02 PM, “Sappy85” <robert.wittkopf@…380…> wrote:

Hi, yes that helps a lot, reading in the boundaries from a shapefile.

But does anybody know, how avoid the “double inner borders”? Coastlines seem

to have a thinner border. Borders between two countries be drawn twice.

<http://matplotlib.1069221.n5.nabble.com/file/n44757/map.png>

Regards

View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755p44757.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


New Year. New Location. New Benefits. New Data Center in Ashburn, VA.

GigeNET is offering a free month of service with a new server in Ashburn.

Choose from 2 high performing configs, both with 100TB of bandwidth.

Higher redundancy.Lower latency.Increased capacity.Completely compliant.

http://p.sf.net/sfu/gigenet


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Hi Ben,

i run the process as user "root" on a virtual linux server. Is this a
problem?

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755p44759.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I would like to draw very, very simple maps of only europe in matplotlib /
basemap, which takes very much time (around 10 seconds!). This is just
unreal!? Setting of resolution is only "l" (low).
I need to plot hundreds of those maps every few hours. This would be
impossible!!? :frowning:

Here is the very simple code:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

m = Basemap(projection='stere',lon_0=5,lat_0=90.0,rsphere=6371200.,\

llcrnrlon=-25.0,urcrnrlon=72.0,llcrnrlat=26.0,urcrnrlat=65.0,resolution='l')

You can save a lot of time by pickling the Basemap instance at this point, saving it to a cache. Then the next time, just pickle.load it from the cache.

Eric

···

On 2015/01/24 6:11 AM, Sappy85 wrote:

m.drawcoastlines(linewidth=0.2)
m.drawcountries(linewidth=0.2)
plt.savefig('/var/www/map.png')

Hope you can help! :frowning:

Regards

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

creating a pickle of the Basmap instance was the correct way. Now it works
great! Thank's all for that quick and helpful support!

Solution as follows:

m = Basemap (...)
pickle.dump(m,open('map.pickle','wb'),-1) # pickle it

for ... : # loop to generate x plots
    pickle.load(open('map.pickle','rb')) # load here the above pickle
    # do some other stuff

Regards
Sappy85

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-maps-with-matplotlib-basemap-very-slow-tp44755p44761.html
Sent from the matplotlib - users mailing list archive at Nabble.com.