Python Matplotlib-注释在图表上重叠,如何将它们垂直均匀分布?

Python Matplotlib-注释在图表上重叠,如何将它们垂直均匀分布?,python,matplotlib,annotations,Python,Matplotlib,Annotations,我有一张图表,95%的置信区间作为补丁。一些数据点自然会重叠。因此,我需要将点标签动态隔开,以使其具有可读性。我有下面的代码。如您所见,标签当前重叠。有什么建议可以让它们不重叠吗 import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as patches import matplotlib.transforms as transforms from matplotlib.font_manager

我有一张图表,95%的置信区间作为补丁。一些数据点自然会重叠。因此,我需要将点标签动态隔开,以使其具有可读性。我有下面的代码。如您所见,标签当前重叠。有什么建议可以让它们不重叠吗

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.transforms as transforms

from matplotlib.font_manager import FontProperties
from matplotlib.pyplot import *

mypath = ['1,0.025','1.01,0.05','1.02,0.035','1.03,0.040']

fig = plt.figure()
ax = fig.add_subplot(111)
Distances = []
Confidence_Intervals = []

for line in mypath:
    Distances.append(float(line.split(',')[0].strip()))
    Confidence_Intervals.append(float(line.split(',')[1].strip()))

ind = np.arange(len(Distances))
data = np.array(Distances)
y_error = np.array(Confidence_Intervals)
circles = []
plt.xlim(-1,1)
plt.ylim(0.8,1.1)

for a in range(len(ind)):
    ax.scatter(0, data[a], s=60, color='Black')
    trans = transforms.blended_transform_factory(ax.transData, ax.transData)
    circles.append(patches.Circle((0,data[a]),y_error[a], transform=trans, facecolor='yellow', alpha=0.5))

fig.set_size_inches(24,12)
for circle in circles:
    ax.add_patch(circle)
labels = ['{0}'.format(i) for i in range(len(data))]

for label, x, y in zip(labels, ind, data):
    plt.annotate(
        label, 
        xy = (0, y), xytext = (100, 0),
        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'))

plt.grid(True)
plt.legend(loc=0, scatterpoints = 1)
plt.ylabel('Pairwise distance (FastTree)')
plt.xlabel('Clade pairing')
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.title('Sample Patch Chart')
axes().set_aspect('equal', 'datalim')
plt.show()