下面是一些基于ImportanceOfBeingErnest的注释方法(2)的代码。
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cmx
from matplotlib.patches import Rectangle
fig, ax = plt.subplots(1)
plt.clf()
plt.plot([0,100], [0,100], '--', linewidth=3, color='k', label = 'start')
plt.plot([100,100],[0,100], '-.', linewidth=3, color = 'k', label = 'stop')
jet = plt.get_cmap('jet')
cNorm = colors.Normalize(vmin=0, vmax=99)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)
scalarMap.set_array([])
for offset in range(1,100):
colorVal = scalarMap.to_rgba(offset)
plt.plot([offset, 100], [0,100], color=colorVal)
plt.gca().add_patch(Rectangle((0.1, 45), 40, 55, edgecolor='gray',
linewidth=3, fill=False))
plt.gca().text(25, 90, "-- start")
plt.gca().text(25, 80, "-. stop")
plt.gca().text(15, 50, " offset")
cax = fig.add_axes([0.18, 0.48, 0.03, 0.35])
plt.colorbar(scalarMap, cax = cax, ticks=[range(0, 100, 10)],
orientation='vertical')
plt.show()