python - Matplotlib - Annotations overlapping on chart, how do I evenly distribute them vertically? -


i have chart, 95% confidence intervals patches. naturally of data points overlap. because of this, need point labels dynamically spaced human readable. have following code below. can see labels overlap. suggestions how them not overlap?

import numpy np import matplotlib.pyplot plt import matplotlib.patches patches import matplotlib.transforms transforms  matplotlib.font_manager import fontproperties 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 = []  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)  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) circle in circles:     ax.add_patch(circle) labels = ['{0}'.format(i) in range(len(data))]  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() 

enter image description here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -