Boston¶
In [1]:
Copied!
'''
@version: 1.0.0
@date: 2023/05/18
@brief: Draw a map of Boston with elevation data.
This script uses the mpl_toolkits.basemap package
to draw a map of Boston with a colorbar showing elevation data.
The map is centered on Boston and shows its surrounding seas and countries.
main.py
'''
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
# Set the latitudinal and longitudinal limits of the map for Boston.
# minLat, maxLat = 40.5, 42.5
minLat, maxLat = 40.5, 43
# minLon, maxLon = -71.25, -69.75
minLon, maxLon = -72, -69.75
# Create a figure and axes object.
fig = plt.figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# Create a Basemap object with the specified projection and limits.
m = Basemap(
projection='cyl',
resolution='h',
llcrnrlat=minLat,
urcrnrlat=maxLat,
llcrnrlon=minLon,
urcrnrlon=maxLon,
ax=ax
)
# Draw the blue marble background.
m.bluemarble()
# Add the coastline and country boundaries.
m.drawcoastlines(color='k')
m.drawcountries(color='k')
# Add the parallels and meridians.
parallels = np.arange(40.5, 42.6, 0.5)
meridians = np.arange(-71.25, -69.74, 0.5)
m.drawparallels(
parallels,
labels=[1, 0, 0, 0],
fontsize=10,
linewidth=0.5
)
m.drawmeridians(
meridians,
labels=[0, 0, 0, 1],
fontsize=10,
linewidth=0.5
)
# Set the title of the plot.
plt.title('Map of Boston', fontsize=20)
plt.show()
'''
@version: 1.0.0
@date: 2023/05/18
@brief: Draw a map of Boston with elevation data.
This script uses the mpl_toolkits.basemap package
to draw a map of Boston with a colorbar showing elevation data.
The map is centered on Boston and shows its surrounding seas and countries.
main.py
'''
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
# Set the latitudinal and longitudinal limits of the map for Boston.
# minLat, maxLat = 40.5, 42.5
minLat, maxLat = 40.5, 43
# minLon, maxLon = -71.25, -69.75
minLon, maxLon = -72, -69.75
# Create a figure and axes object.
fig = plt.figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# Create a Basemap object with the specified projection and limits.
m = Basemap(
projection='cyl',
resolution='h',
llcrnrlat=minLat,
urcrnrlat=maxLat,
llcrnrlon=minLon,
urcrnrlon=maxLon,
ax=ax
)
# Draw the blue marble background.
m.bluemarble()
# Add the coastline and country boundaries.
m.drawcoastlines(color='k')
m.drawcountries(color='k')
# Add the parallels and meridians.
parallels = np.arange(40.5, 42.6, 0.5)
meridians = np.arange(-71.25, -69.74, 0.5)
m.drawparallels(
parallels,
labels=[1, 0, 0, 0],
fontsize=10,
linewidth=0.5
)
m.drawmeridians(
meridians,
labels=[0, 0, 0, 1],
fontsize=10,
linewidth=0.5
)
# Set the title of the plot.
plt.title('Map of Boston', fontsize=20)
plt.show()
In [ ]:
Copied!