我试图在我的图表中停止注释文本重叠.在接受Matplotlib重叠注释的答案中建议的方法看起来非常有希望,但是对于条形图而言.我无法将"轴"方法转换为我想要做的事情,而且我不明白文本是如何排列的.
import sys
import matplotlib.pyplot as plt
# start new plot
plt.clf()
plt.xlabel("Proportional Euclidean Distance")
plt.ylabel("Percentage Timewindows Attended")
plt.title("Test plot")
together = [(0, 1.0, 0.4), (25, 1.0127692669427917, 0.41), (50, 1.016404709797609, 0.41), (75, 1.1043426359673716, 0.42), (100, 1.1610446924342996, 0.44), (125, 1.1685687930691457, 0.43), (150, 1.3486407784550272, 0.45), (250, 1.4013999168008104, 0.45)]
together.sort()
for x,y,z in together:
plt.annotate(str(x), xy=(y, z), size=8)
eucs = [y for (x,y,z) in together]
covers = [z for (x,y,z) in together]
p1 = plt.plot(eucs,covers,color="black", alpha=0.5)
plt.savefig("test.png")
Run Code Online (Sandbox Code Playgroud)
图像(如果有效)可以在这里找到(此代码):

而 …
我想用一些文本注释图形中的条形,但如果条形图靠近并具有相当的高度,则注释高于ea.其他因而难以阅读(注释的坐标取自条形位置和高度).
如果发生碰撞,有没有办法改变其中一个?
编辑:条纹非常薄,有时非常接近,所以只是垂直对齐并不能解决问题...
图片可能会澄清一些事情:

我使用matplotlib绘制散点图:

并根据matplotlib中的提示使用透明框标记气泡:如何在分散自动放置箭头上注释点?
这是代码:
if show_annote:
for i in range(len(x)):
annote_text = annotes[i][0][0] # STK_ID
ax.annotate(annote_text, xy=(x[i], y[i]), xytext=(-10,3),
textcoords='offset points', ha='center', va='bottom',
bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.2),
fontproperties=ANNOTE_FONT)
Run Code Online (Sandbox Code Playgroud)
以及由此产生的情节:

但是仍然存在减少重叠的改进空间(例如标签框偏移固定为(-10,3)).是否有算法可以:
我只是想让人眼看起来很简单,所以有些重叠是可以的,不像http://en.wikipedia.org/wiki/Automatic_label_placement所暗示的那样严格.并且图表中的气泡数量大多数时间都不到150.
我发现所谓的Force-based label placement http://bl.ocks.org/MoritzStefaner/1377729 非常有趣.我不知道是否有任何python代码/包可用于实现该算法.
我不是一个学术人员而且没有寻找最佳解决方案,我的python代码需要标记许多图表,因此速度/内存在考虑范围内.
我正在寻找一种快速有效的解决方案.有关此主题的任何帮助(代码,算法,提示,想法)?谢谢.