用对数轴注释散点图中的点

时间:2013-12-11 10:57:55

标签: python matplotlib plot

我使用matplotlib生成几个点的散点图。每个点都应注明标签。我试图将标签随机放置在点坐标周围的圆上。但是,我没有得到满意的结果。一个主要问题是y轴需要以对数方式进行缩放。

什么是放置标签的简单方法,使它们不重叠并且在视觉上与它们的点保持恒定距离?

import random
import math

algos = [plm, plm2, plp, plmr2, plmr, clutbb, rg, cggc, cggci, epp_plm, louvain, epp_plm2, epp_plmr2]
labels = ["PLM(o)", "PLM", "PLP", "PLMR", "PLMR(o)", "CLU_TBB", "RG", "CGGC", "CGGCi", "EPP(o)", "Louvain", "EPP_PLM", "EPP_PLMR"]
scores = [paretoScore(algo, plm2) for algo in algos]

def labelcoord(coord, r, s):
    (x, y) = coord
    phi = random.uniform(0, 2 * math.pi)
    return (x + r * math.cos(phi), y + s * math.sin(phi))


scatter(*(zip(*scores)), color="Green")
xlabel("modularity score")
yscale("symlog")
ylabel("time score")
for (label, score) in zip(labels, scores):
    annotate(label, xy=score, xytext=labelcoord(score, 0.02, 10),
             fontsize=12,
             arrowprops = dict(arrowstyle = '->', color="lightgray", connectionstyle = 'arc3,rad=0'))

enter image description here

0 个答案:

没有答案