[Matplotlib-users] What is the fastest way to plot map using Basemap and shapefile?

sundar_ima sundar_ima at rediffmail.com
Thu Feb 11 13:36:39 EST 2016


As the title suggest What is the fastest way to plot map using Basemap and
python?

I have a requirement of plotting 100s of images for a area where basemap
does not have the better resolution. Therefore I have choose to plot
shapefile for boundary and basemap for projection. I have already read this
file https://github.com/matplotlib/basemap/blob/master/examples/hires.py and
it seems to be the way ahead for plotting maps faster. However, when I tried
to do the same example for  shapefile, the current axis gets removed. Here
is my work flow:-

import required modeules

# initialise basemap
m = Basemap(projection='merc', llcrnrlat=south, urcrnrlat=north,
            llcrnrlon=west, urcrnrlon=east, resolution='c',
area_thresh=10000.)

# I have a seperate plotting function
def drawmap(data, string1, strin2, strin3):
    print 'Plotting the actual map.'
    F = plt.gcf()  # Gets the current figure for later use
    ..... do some code

def plot_variable():
    .... some code
    # call the drawmap function
    drawmap(data, string1, strin2, strin3)
    
plot_variable()

If I use the following line just after Basemap instance all works fine
without any error (though that is what I want as the boundaries wont be
plotted later). The same line included with the def drawmap(data, string1,
strin2, strin3): function also works fine but increases the plot time as it
has to read every time the drawmap function is called.
m.readshapefile('data/gis-data/NaturalEarth_10M_India_corrected/world_countries/ne_10m_admin_0_countries_lakes',
'ne_10m_admin_0_countries_lakes', drawbounds=True, linewidth=0.7)

Then I tried to pickle the above line from outside the drawmap(data,
string1, strin2, strin3) function and reload it after whenever drawmap is
called. However, I get the following error:-

    F.add_axes(cax)  # Adds the new axis to the figure as the current
working axis
  File
"/home/sundar/anaconda2/lib/python2.7/site-packages/matplotlib/figure.py",
line 901, in add_axes
    raise ValueError(msg)
ValueError: The Axes must have been created in the present figure


Any solution for above or any I dea to plot faster is appreciated.



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/What-is-the-fastest-way-to-plot-map-using-Basemap-and-shapefile-tp46743.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


More information about the Matplotlib-users mailing list