I need to plot the map of a country (it may be any country according to the requirement) without specifying llcrnrlat,urcrnrlat,llcrnrlon and urcrnrlon.
Asked
Active
Viewed 646 times
1 Answers
0
You may use Basemap without specifying the projection and coordinates of the map to read a shapefile. One can e.g. take the shapes of the countries from here.
Example for a map of Switzerland:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np
m = Basemap()
fn = r"ne_10m_admin_0_countries\ne_10m_admin_0_countries"
m.readshapefile(fn, 'shf', drawbounds = False)
def draw_country(country, ax=None,**kwargs):
if ax == None: ax=plt.gca()
for info, shape in zip(m.shf_info, m.shf):
if info['NAME'] == country:
s = np.array(shape)
ax.plot(s[:,0], s[:,1], alpha=0)
p= Polygon(s, **kwargs)
ax.add_artist(p)
fig, ax = plt.subplots()
ax.set_aspect("equal")
draw_country("Switzerland",fill=True, facecolor= "crimson", edgecolor='none', alpha=0.7)
# try with other contries like 'Ireland', "Venezuela" etc
plt.show()
The drawback is of course that when not specifying the projection, the country shape may not be what we're used to from usual maps.
For plotting countries on a map with a legend, see e.g. this question.

Community
- 1
- 1

ImportanceOfBeingErnest
- 321,279
- 53
- 665
- 712