首页 > 解决方案 > 避免重叠注释

问题描述

我在下面有一个注释散点的代码

        for x,y in zip(xs,ys):

            label = "{:.2f}%".format(y)

            plt.annotate(label, # this is the text
                         (x,y), # this is the point to label
                         textcoords="offset points", # how to position the text
                         xytext=(0,10), # distance from text to points (x,y)
                         ha='center') # horizontal alignment can be left, right or center
        

我的结果图是这样的:我有很多点靠得太近,导致注释重叠。任何人都知道如何根据我当前的代码来避免它?

在此处输入图像描述

标签: pythonmatplotliboverlapannotate

解决方案


推荐阅读