python - Matplotlib - Chart using patch circles with size equivalent to error bars. Scaling issue. Circles are squashed? -


i trying produce chart using patches. code below, know why these end being squashed , not circular, want? unfortunately not have enough rep post picture... sample code self contained, i.e. should able run generate graph. patches seem change shape when plot resized. them stay fixed.

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.25','2,0.5','3,0.35','4,0.40']  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 = []  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)  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(title) plt.xlim(-0.6,0.6) plt.show() 

thanks suggestion joe kington. right. aspect ratio not being set.

i added following line:

axes().set_aspect('equal', 'datalim')

the patches keeping width independently of chart size. final code below.

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.25','2,0.5','3,0.35','4,0.40']  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 = [] print y_error plt.xlim(-0.6,0.6)  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)  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(title) axes().set_aspect('equal', 'datalim') plt.show() 

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 -