在rcParams中实现了对prop_cycle属性markevery的支持

此示例演示了一个发布 #8576 的工作解决方案,通过rcParams为axes.prop_cycle分配提供对markevery属性的完全支持。从markevery演示中使用相同的markevery案例列表。

使用每列的移位正弦曲线渲染绘图,每个正弦曲线都有一个唯一的市场价值。

markevery支持1

  1. from cycler import cycler
  2. import numpy as np
  3. import matplotlib as mpl
  4. import matplotlib.pyplot as plt
  5. # Define a list of markevery cases and color cases to plot
  6. cases = [None,
  7. 8,
  8. (30, 8),
  9. [16, 24, 30],
  10. [0, -1],
  11. slice(100, 200, 3),
  12. 0.1,
  13. 0.3,
  14. 1.5,
  15. (0.0, 0.1),
  16. (0.45, 0.1)]
  17. colors = ['#1f77b4',
  18. '#ff7f0e',
  19. '#2ca02c',
  20. '#d62728',
  21. '#9467bd',
  22. '#8c564b',
  23. '#e377c2',
  24. '#7f7f7f',
  25. '#bcbd22',
  26. '#17becf',
  27. '#1a55FF']
  28. # Configure rcParams axes.prop_cycle to simultaneously cycle cases and colors.
  29. mpl.rcParams['axes.prop_cycle'] = cycler(markevery=cases, color=colors)
  30. # Create data points and offsets
  31. x = np.linspace(0, 2 * np.pi)
  32. offsets = np.linspace(0, 2 * np.pi, 11, endpoint=False)
  33. yy = np.transpose([np.sin(x + phi) for phi in offsets])
  34. # Set the plot curve with markers and a title
  35. fig = plt.figure()
  36. ax = fig.add_axes([0.1, 0.1, 0.6, 0.75])
  37. for i in range(len(cases)):
  38. ax.plot(yy[:, i], marker='o', label=str(cases[i]))
  39. ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
  40. plt.title('Support for axes.prop_cycle cycler with markevery')
  41. plt.show()

下载这个示例