Question

I am using Basemap within Matplotlib to draw a map of the United States. However, I cannot seem to be able to remove Mexico or Canada to just have the US shown. I need to draw the states as well. Currently, my code is:

self.map = Basemap(llcrnrlon=-119, llcrnrlat=22, urcrnrlon=-64,
                               urcrnrlat=49, projection='lcc', lat_1=33, lat_2=45,
                               lon_0=-95, resolution='i', area_thresh=10000,ax=self.axes)

self.map.drawcoastlines()
self.map.drawcountries()
self.map.drawstates()
self.figure.canvas.draw()

This draws the US with some Mexico and Canada shown. If i comment out self.map.drawcountries(), then the southern and northern US borders are removed, so this doesn't help. If i comment out self.map.drawcoastlines(), this removes the East and West borders. I cannot find any other command that allows me to have just the US (with states) drawn.

Any ideas? Thanks!

Was it helpful?

Solution

You need to draw the polygons yourself. This can be done by reading a shapefile. See the fillstates.py example, which plots the US states (without Mexico or Canada).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top