简单的Legend02

简单的Legend02示例

  1. import matplotlib.pyplot as plt
  2. fig, ax = plt.subplots()
  3. line1, = ax.plot([1, 2, 3], label="Line 1", linestyle='--')
  4. line2, = ax.plot([3, 2, 1], label="Line 2", linewidth=4)
  5. # Create a legend for the first line.
  6. first_legend = ax.legend(handles=[line1], loc='upper right')
  7. # Add the legend manually to the current Axes.
  8. ax.add_artist(first_legend)
  9. # Create another legend for the second line.
  10. ax.legend(handles=[line2], loc='lower right')
  11. plt.show()

下载这个示例