The basemap library (closely linked with matplotlib) contains a database with several boundaries. Thus, it is easy to represent the limits of countries, states and counties, without having to load a shape file. Here is how to show these 3 types of boundaries:
-
#286 Country boundaries
To show the countries on your map, use the map.drawcountries function. Note that you can custom this boundaries: color, width, alpha..
# Libraries from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt # Initialize the map map = Basemap(llcrnrlon=-160, llcrnrlat=-60,urcrnrlon=160,urcrnrlat=70) # Continent and countries! map.drawmapboundary(fill_color='#A6CAE0') map.fillcontinents(color='#e6b800',lake_color='#e6b800') map.drawcountries(color="white") plt.show()
-
#286 Counties boundaries
To add counties, use… drawcounties() ! 🙂
# libraries from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt # initialise map = Basemap(llcrnrlon=-130, llcrnrlat=25, urcrnrlon=-65.,urcrnrlat=52.,resolution='i', lat_0 = 40., lon_0 = -80) # show counties map.drawmapboundary(fill_color='#A6CAE0') map.fillcontinents(color='#e6b800',lake_color='#A6CAE0') map.drawcounties() plt.show()
-
#286 State boundaries
To add states, use… drawstates() ! 🙂
# libraries from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt # initialise map = Basemap(llcrnrlon=-130, llcrnrlat=25, urcrnrlon=-65.,urcrnrlat=52.,resolution='i', lat_0 = 40., lon_0 = -80) # map states map.drawmapboundary(fill_color='#A6CAE0') map.fillcontinents(color='#e6b800',lake_color='#A6CAE0') map.drawstates() map.drawcountries() plt.show()