Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/counties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

def draw_map_background(m, ax):
ax.set_axis_bgcolor('#729FCF')
m.fillcontinents(color='#FAFAFA', ax=ax, zorder=0)
m.drawcounties(ax=ax)
m.drawstates(ax=ax)
m.drawcountries(ax=ax)
m.drawcoastlines(ax=ax)
KM = 1000.
clat = 39.3
clon = -94.7333
wid = 5500 * KM
hgt = 3500 * KM
m = Basemap(width=wid, height=hgt, rsphere=(6378137.00,6356752.3142),
resolution='i', area_thresh=2500., projection='lcc',
lat_1=38.5, lat_2=38.5, lat_0=clat, lon_0=clon)
fig = plt.figure()
ax = fig.add_subplot(111)
draw_map_background(m, ax)
plt.show()
55 changes: 51 additions & 4 deletions lib/mpl_toolkits/basemap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ def _clipcircle(self,ax,coll):
item.set_clip_path(c)
return coll,c

def drawcoastlines(self,linewidth=1.,color='k',antialiased=1,ax=None,zorder=None):
def drawcoastlines(self,linewidth=1.,linestyle='solid',color='k',antialiased=1,ax=None,zorder=None):
"""
Draw coastlines.

Expand All @@ -1652,6 +1652,7 @@ def drawcoastlines(self,linewidth=1.,color='k',antialiased=1,ax=None,zorder=None
Keyword Description
============== ====================================================
linewidth coastline width (default 1.)
linestyle coastline linestyle (default solid)
color coastline color (default black)
antialiased antialiasing switch for coastlines (default True).
ax axes instance (overrides default axes instance)
Expand All @@ -1668,6 +1669,7 @@ def drawcoastlines(self,linewidth=1.,color='k',antialiased=1,ax=None,zorder=None
ax = ax or self._check_ax()
coastlines = LineCollection(self.coastsegs,antialiaseds=(antialiased,))
coastlines.set_color(color)
coastlines.set_linestyle(linestyle)
coastlines.set_linewidth(linewidth)
coastlines.set_label('_nolabel_')
if zorder is not None:
Expand All @@ -1679,7 +1681,7 @@ def drawcoastlines(self,linewidth=1.,color='k',antialiased=1,ax=None,zorder=None
self.set_axes_limits(ax=ax)
return coastlines

def drawcountries(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
def drawcountries(self,linewidth=0.5,linestyle='solid',color='k',antialiased=1,ax=None,zorder=None):
"""
Draw country boundaries.

Expand All @@ -1689,6 +1691,7 @@ def drawcountries(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None
Keyword Description
============== ====================================================
linewidth country boundary line width (default 0.5)
linestyle coastline linestyle (default solid)
color country boundary line color (default black)
antialiased antialiasing switch for country boundaries (default
True).
Expand All @@ -1710,6 +1713,7 @@ def drawcountries(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None
ax = ax or self._check_ax()
countries = LineCollection(self.cntrysegs,antialiaseds=(antialiased,))
countries.set_color(color)
countries.set_linestyle(linestyle)
countries.set_linewidth(linewidth)
countries.set_label('_nolabel_')
if zorder is not None:
Expand All @@ -1721,7 +1725,7 @@ def drawcountries(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None
self.set_axes_limits(ax=ax)
return countries

def drawstates(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
def drawstates(self,linewidth=0.5,linestyle='solid',color='k',antialiased=1,ax=None,zorder=None):
"""
Draw state boundaries in Americas.

Expand All @@ -1731,6 +1735,7 @@ def drawstates(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
Keyword Description
============== ====================================================
linewidth state boundary line width (default 0.5)
linestyle coastline linestyle (default solid)
color state boundary line color (default black)
antialiased antialiasing switch for state boundaries
(default True).
Expand All @@ -1752,6 +1757,7 @@ def drawstates(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
ax = ax or self._check_ax()
states = LineCollection(self.statesegs,antialiaseds=(antialiased,))
states.set_color(color)
states.set_linestyle(linestyle)
states.set_linewidth(linewidth)
states.set_label('_nolabel_')
if zorder is not None:
Expand All @@ -1763,7 +1769,46 @@ def drawstates(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
self.set_axes_limits(ax=ax)
return states

def drawrivers(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
def drawcounties(self,linewidth=0.1,linestyle='solid',color='k',antialiased=1,
ax=None,zorder=None,drawbounds=False):
"""
Draw county boundaries in US. The county boundary shapefile
originates with the NOAA Coastal Geospatial Data Project
(http://coastalgeospatial.noaa.gov/data_gis.html).

.. tabularcolumns:: |l|L|

============== ====================================================
Keyword Description
============== ====================================================
linewidth county boundary line width (default 0.1)
linestyle coastline linestyle (default solid)
color county boundary line color (default black)
antialiased antialiasing switch for county boundaries
(default True).
ax axes instance (overrides default axes instance)
zorder sets the zorder for the county boundaries (if not
specified, uses default zorder for
matplotlib.patches.LineCollections).
============== ====================================================

returns a matplotlib.patches.LineCollection object.
"""
ax = ax or self._check_ax()
gis_file = os.path.join(basemap_datadir,'UScounties')
county_info = self.readshapefile(gis_file,'counties',drawbounds=drawbounds)
counties = [coords for coords in self.counties]
counties = LineCollection(counties)
counties.set_linestyle(linestyle)
counties.set_linewidth(linewidth)
counties.set_color(color)
counties.set_label('counties')
if zorder:
counties.set_zorder(zorder)
ax.add_collection(counties)
return counties

def drawrivers(self,linewidth=0.5,linestyle='solid',color='k',antialiased=1,ax=None,zorder=None):
"""
Draw major rivers.

Expand All @@ -1773,6 +1818,7 @@ def drawrivers(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
Keyword Description
============== ====================================================
linewidth river boundary line width (default 0.5)
linestyle coastline linestyle (default solid)
color river boundary line color (default black)
antialiased antialiasing switch for river boundaries (default
True).
Expand All @@ -1794,6 +1840,7 @@ def drawrivers(self,linewidth=0.5,color='k',antialiased=1,ax=None,zorder=None):
ax = ax or self._check_ax()
rivers = LineCollection(self.riversegs,antialiaseds=(antialiased,))
rivers.set_color(color)
rivers.set_linestyle(linestyle)
rivers.set_linewidth(linewidth)
rivers.set_label('_nolabel_')
if zorder is not None:
Expand Down
Binary file added lib/mpl_toolkits/basemap/data/UScounties.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions lib/mpl_toolkits/basemap/data/UScounties.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file added lib/mpl_toolkits/basemap/data/UScounties.shp
Binary file not shown.
Binary file added lib/mpl_toolkits/basemap/data/UScounties.shx
Binary file not shown.