In this Matplotlib tutorial, we continue with the Basemap geographic plotting extension. We're going to show some of the customization options available to us.
First, taking our starting code from the previous tutorial:
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt m = Basemap(projection='mill') m.drawcoastlines() plt.show()
We can then start by zooming into specific areas like:
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt m = Basemap(projection='mill', llcrnrlat = -40, llcrnrlon = -40, urcrnrlat = 50, urcrnrlon = 75) m.drawcoastlines() plt.show()
The parameters here are:
Also, coordinates are converted, where western and southern coordinates are negatives, and the northern and eastern coordinates are positives.
With these coordinates, Basemap selects the area between them.
Next, we can use something like:
m.drawcountries(linewidth=2)
This will draw countries, and make their separating lines with a line width of 2.
Another option is:
m.drawstates(color='b')
This will draw states with blue lines.
You can also do:
m.drawcounties(color='darkred')
This draws counties.
So, with code currently like:
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt m = Basemap(projection='mill', llcrnrlat = -90, llcrnrlon = -180, urcrnrlat = 90, urcrnrlon = 180) m.drawcoastlines() m.drawcountries(linewidth=2) m.drawstates(color='b') m.drawcounties(color='darkred') plt.title('Basemap Tutorial') plt.show()
Hard to tell here, but we have defined county lines in the United States. We can zoom in to Basemap graphs like other graphs using the magnifying glass, giving us:
Another useful parameter is the "resolution" option with the Basemap call:
m = Basemap(projection='mill', llcrnrlat = -90, llcrnrlon = -180, urcrnrlat = 90, urcrnrlon = 180, resolution='l')
The resolution options:
For the higher resolutions, you really should start zoomed in quite far, otherwise you're probably just wasting processing.
Another option is to plot topography with etopo(), like:
m.etopo()
Plotting this with the drawcountries method gives you:
Finally, there is a blue marbling version, which you can invoke with
m.bluemarble()
Giving you:
Code up to this point:
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt m = Basemap(projection='mill', llcrnrlat = -90, llcrnrlon = -180, urcrnrlat = 90, urcrnrlon = 180, resolution='l') m.drawcoastlines() m.drawcountries(linewidth=2) ##m.drawstates(color='b') ##m.drawcounties(color='darkred') #m.fillcontinents() #m.etopo() m.bluemarble() plt.title('Basemap Tutorial') plt.show()