简单的Legend01

简单的Legend01示例

  1. import matplotlib.pyplot as plt
  2. plt.subplot(211)
  3. plt.plot([1, 2, 3], label="test1")
  4. plt.plot([3, 2, 1], label="test2")
  5. # Place a legend above this subplot, expanding itself to
  6. # fully use the given bounding box.
  7. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left',
  8. ncol=2, mode="expand", borderaxespad=0.)
  9. plt.subplot(223)
  10. plt.plot([1, 2, 3], label="test1")
  11. plt.plot([3, 2, 1], label="test2")
  12. # Place a legend to the right of this smaller subplot.
  13. plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
  14. plt.show()

下载这个示例