线型样式参考

Matplotlib附带的线型参考。

线型样式参考图示

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. color = 'cornflowerblue'
  4. points = np.ones(5) # Draw 5 points for each line
  5. text_style = dict(horizontalalignment='right', verticalalignment='center',
  6. fontsize=12, fontdict={'family': 'monospace'})
  7. def format_axes(ax):
  8. ax.margins(0.2)
  9. ax.set_axis_off()
  10. # Plot all line styles.
  11. fig, ax = plt.subplots()
  12. linestyles = ['-', '--', '-.', ':']
  13. for y, linestyle in enumerate(linestyles):
  14. ax.text(-0.1, y, repr(linestyle), **text_style)
  15. ax.plot(y * points, linestyle=linestyle, color=color, linewidth=3)
  16. format_axes(ax)
  17. ax.set_title('line styles')
  18. plt.show()

下载这个示例