import matplotlib.pyplot as plt import numpy as np
# Fixing random state for reproducibility np.random.seed(19680801)
x = np.random.random(20) y = np.random.random(20)
分散的顶部的线
1 2 3 4 5 6 7 8 9 10 11 12
plt.figure() plt.subplot(211) plt.plot(x, y, 'C3', lw=3) plt.scatter(x, y, s=120) plt.title('Lines on top of dots')
# Scatter plot on top of lines plt.subplot(212) plt.plot(x, y, 'C3', zorder=1, lw=3) plt.scatter(x, y, s=120, zorder=2) plt.title('Dots on top of lines') plt.tight_layout()
一个新的图像,带有单独订购的物品
1 2 3 4 5 6 7 8 9 10 11
x = np.linspace(0, 2*np.pi, 100) plt.rcParams['lines.linewidth'] = 10 plt.figure() plt.plot(x, np.sin(x), label='zorder=10', zorder=10) # on top plt.plot(x, np.sin(1.1*x), label='zorder=1', zorder=1) # bottom plt.plot(x, np.sin(1.2*x), label='zorder=3', zorder=3) plt.axhline(0, label='zorder=2', color='grey', zorder=2) plt.title('Custom order of elements') l = plt.legend(loc='upper right') l.set_zorder(20) # put the legend on top plt.show()