python - Organizing text on pie charts at matplotlib -


i've learned basics of plotting pie charts (through tutorial , examples here), don't manage put suptitle above chart (i need maybe reduce pie chart size, how do it?). want place text box added in bottom right or left side of pie chart. if can give hint great!

(the function takes string name of channel, list 4 percentages, int mass , flag save_figures if want save figure)

def plot_channel(channel,percentages, mass, save_figures):     # build rectangle in axes coords     left, width = .25, .5     bottom, height = .25, .5     right = left + width     top = bottom + height      channel = ''.join(i in channel if in 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')        nu_energy , d_plus_p_energy, e_energy, gamma_energy  = percentages        # slices ordered , plotted counter-clockwise.     labels = [r'$e_{\nu} / e_{tot}$ = %.3f'%nu_energy,                r'$e_{d+p} / e_{tot}$ = %.3f'%d_plus_p_energy,               r'$e_{e} / e_{tot}$ = %.3f'%e_energy,               r'$e_{\gamma} / e_{tot}$ = %.3f'%gamma_energy]     sizes = [nu_energy , d_plus_p_energy, e_energy, gamma_energy]     colors = ['gold','red','green', 'lightskyblue']     explode = (0.1, 0,0,0)     patches, texts = plt.pie(sizes, colors=colors)#, startangle=90) ** not working reason     plt.legend(patches, labels, loc = "best")     e_gamma_e = e_energy + gamma_energy     plt.text(right, bottom,               r'$e_{\gamma + e} / e_{tot}$ = %.3f'%e_gamma_e,              horizontalalignment='left',              verticalalignment='bottom',              bbox=dict(facecolor='white', alpha=0.5), fontsize=30)       #plt.pie(sizes, explode=explode, labels=labels, colors=colors,             #autopct='%1.1f%%', shadow=true)     # set aspect ratio equal pie drawn circle.     plt.axis('equal')     plt.suptitle(r'dm dm $\rightarrow$ $%s$ + $%s$'%(channel,channel),position=(left,top),                  bbox=dict(facecolor='0.8',), fontsize=30)     plt.tight_layout()     if save_figures:         plt.savefig("./figures/energy_distribution_for_channel_{}.png".format(channel))     else:         plt.show()      plt.close() 

example of 1 of pie charts created code

try this:

import matplotlib.pyplot plt  channel,percentages, mass = "ab",[0.2,0.2,0.1,0.5], 10  # build rectangle in axes coords left, width = .25, .5 bottom, height = .25, .5 right = left + width top = bottom + height  channel = ''.join(i in channel if in 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz') nu_energy , d_plus_p_energy, e_energy, gamma_energy  = percentages    # slices ordered , plotted counter-clockwise. labels = [r'$e_{\nu} / e_{tot}$ = %.3f' % nu_energy,            r'$e_{d+p} / e_{tot}$ = %.3f' % d_plus_p_energy,           r'$e_{e} / e_{tot}$ = %.3f' % e_energy,           r'$e_{\gamma} / e_{tot}$ = %.3f' %gamma_energy] sizes = [nu_energy , d_plus_p_energy, e_energy, gamma_energy] colors = ['gold','red','green', 'lightskyblue'] explode = (0.1, 0,0,0) patches, texts = plt.pie(sizes, colors=colors)#, startangle=90) ** not working reason plt.legend(patches, labels, loc = "best") e_gamma_e = e_energy + gamma_energy #plt.pie(sizes, explode=explode, labels=labels, colors=colors,         #autopct='%1.1f%%', shadow=true) # set aspect ratio equal pie drawn circle. plt.axis('equal') plt.title(r'dm dm $\rightarrow$ $%s$ + $%s$'%(channel,channel),position=(0.5,1),bbox=dict(facecolor='0.8',), fontsize=30) plt.text(-1,-0.98, r'$e_{\gamma + e} / e_{tot}$ = %.3f'%e_gamma_e, bbox=dict(facecolor='white', alpha=0.5), fontsize=14)   plt.tight_layout()  plt.show() 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

python - Scapy Dot11ReassoReq -