我正在寻找一种使用matplotlib在数据点上加双标记的方法。
我们有这样的标记: https://matplotlib.org/examples/lines_bars_and_markers/marker_reference.html
我的问题是,如何在同一位置定位两个标记?例如,要将一个制造商放置在一个数据点上,我们使用“ o”,而我想得到一个“ oo”的效果
答案 0 :(得分:0)
一个可能的解决方案是为每个原始数据点绘制一对彼此稍微偏移的数据点。您可以从原始数据的x坐标中减去一个小值,并有效地使两个符号彼此靠近。这样就可以准确地将标记大小和偏移值缩放为绘图大小的函数,您便可以掌握所描述的内容。但是,这并不像定义一个新的自定义标记那样灵活。
参考this previously answered question之后,我找到了一种以更灵活的方式(使用mathtext符号)完成与您描述的内容类似的方式的方法:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 50.0, 2.0)
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0
s = np.random.rand(*x.shape) * 800 + 500
plt.plot(x, y, 'ko', marker=r'$\mathrm{oo}$', markersize=12)