注釈
Go to the end to download the full example code
zorder (layer)¶
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig, ax = plt.subplots(1,2,figsize=(8,4))
x = np.linspace(-1,1,100)
y = np.linspace(-1,1,100)
x,y = np.meshgrid(x,y)
w = 0.4
x0 = 1 - w
y0 = 1 - w
r0 = patches.Rectangle(xy=(x0,y0), width=w, height=w, ec='#000', fill=True, fc="#000", zorder=1)
r1 = patches.Rectangle(xy=(x0,y0), width=w, height=w, ec='#000', fill=True, fc="#000", zorder=2)
f = lambda x,y: x*y
ax[0].contour(x,y,f(x,y), 100)
ax[1].contour(x,y,f(x,y), 100)
ax[0].set_title("zorder=1 (default)")
ax[1].set_title("zorder=2")
ax[0].add_patch(r0)
ax[1].add_patch(r1)
fig.tight_layout()
plt.show()
Total running time of the script: ( 0 minutes 0.370 seconds)