标记参考

使用Matplotlib参考填充,未填充和自定义标记类型。

有关所有标记的列表,请参阅 matplotlib.markers 文档。 另请参阅 标记填充样式标记路径示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.lines import Line2D
  4. points = np.ones(3) # Draw 3 points for each line
  5. text_style = dict(horizontalalignment='right', verticalalignment='center',
  6. fontsize=12, fontdict={'family': 'monospace'})
  7. marker_style = dict(linestyle=':', color='0.8', markersize=10,
  8. mfc="C0", mec="C0")
  9. def format_axes(ax):
  10. ax.margins(0.2)
  11. ax.set_axis_off()
  12. ax.invert_yaxis()
  13. def nice_repr(text):
  14. return repr(text).lstrip('u')
  15. def math_repr(text):
  16. tx = repr(text).lstrip('u').strip("'").strip("$")
  17. return r"'\${}\$'".format(tx)
  18. def split_list(a_list):
  19. i_half = len(a_list) // 2
  20. return (a_list[:i_half], a_list[i_half:])

填充和未填充标记类型

绘制所有未填充的标记

  1. fig, axes = plt.subplots(ncols=2)
  2. fig.suptitle('un-filled markers', fontsize=14)
  3. # Filter out filled markers and marker settings that do nothing.
  4. unfilled_markers = [m for m, func in Line2D.markers.items()
  5. if func != 'nothing' and m not in Line2D.filled_markers]
  6. for ax, markers in zip(axes, split_list(unfilled_markers)):
  7. for y, marker in enumerate(markers):
  8. ax.text(-0.5, y, nice_repr(marker), **text_style)
  9. ax.plot(y * points, marker=marker, **marker_style)
  10. format_axes(ax)
  11. plt.show()

未填充标记图示

绘制所有填满的标记。

  1. fig, axes = plt.subplots(ncols=2)
  2. for ax, markers in zip(axes, split_list(Line2D.filled_markers)):
  3. for y, marker in enumerate(markers):
  4. ax.text(-0.5, y, nice_repr(marker), **text_style)
  5. ax.plot(y * points, marker=marker, **marker_style)
  6. format_axes(ax)
  7. fig.suptitle('filled markers', fontsize=14)
  8. plt.show()

已填充充标记图示

带有MathText的自定义标记

使用MathText,使用自定义标记符号,例如“$\$ u266B”。有关STIX字体符号的概述,请参阅STIX字体表。另请参阅STIX字体演示

  1. fig, ax = plt.subplots()
  2. fig.subplots_adjust(left=0.4)
  3. marker_style.update(mec="None", markersize=15)
  4. markers = ["$1$", r"$\frac{1}{2}$", "$f$", "$\u266B$",
  5. r"$\mathcircled{m}$"]
  6. for y, marker in enumerate(markers):
  7. ax.text(-0.5, y, math_repr(marker), **text_style)
  8. ax.plot(y * points, marker=marker, **marker_style)
  9. format_axes(ax)
  10. plt.show()

带有MathText的自定义标记图示

下载这个示例