我想为线图中的每个点添加单个标记。但是,这些标签看起来非常混乱。有没有自动排列标签的方法?
df = [(1, 0.02245100099048534), (2, 0.0215730708046943), (3, 0.01631299336674971),
(4, 0.016984572440495845), (5, 0.014226971215895789), (6, 0.013795509799801903),
(7, 0.012542395773929226), (8, 0.013900561275024762), (9, 0.011248011525647568),
(10, 0.01141920039207555), (11, 0.01258716267318257), (12, 0.012786334667111814),
(13, 0.012111888111888111), (14, 0.010556074444144952), (15, 0.008746287867627104),
(16, 0.00975691674713464), (17, 0.008427283613113125), (18, 0.008616608275731465),
(19, 0.009868600403467641), (20, 0.008864811622753016)]
x_2, y_2 = zip(*df)
markers_on = range(0,20)
plt.plot(x_2, y_2, '-bD', markevery=markers_on)
for label, x, y in zip(y_2, x_2, y_2):
plt.annotate(
round(label,4),
xy=(x, y), xytext=(-20, 20),
textcoords='offset points', ha='right', va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0'))