I would like to plot a shape on a basemap. For this, I created a basemap plot and a path plot and included both in one python code snippet. I first draw the baemap and then the path. Afterwards, I draw the plot with plt.show()
. However, both plots are being drawn in seperate images. How can I plot the square on the basemap? Thanks!
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
# =============================================================================
# Basemap
# =============================================================================
plt.figure(figsize=(15,15/2))
m = Basemap(projection='robin', lon_0=0, resolution='c')
m.drawcountries(color='#ffffff', linewidth=0.75)
m.fillcontinents(color='#c0c0c0', lake_color='#e6f5ff')
m.drawmapboundary(fill_color='#e6f5ff', linewidth=1, color='#000000') # Ocean
# =============================================================================
# Path
# =============================================================================
verts = [
(8493400,4307750), # P0
(8493400,12923250), # P1
(25480200,12923250), # P2
(25480200,4307750), # P3
(0,0)
]
codes = [
Path.MOVETO,
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.CLOSEPOLY,
]
path = Path(verts, codes)
fig, ax = plt.subplots()
patch = patches.PathPatch(path, facecolor='orange', lw=2)
ax.add_patch(patch)
ax.set_xlim(0,33973600)
ax.set_ylim(0,17231000)
plt.show()