Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
labels legibility in matplotlib pie charts and bar plots
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="meow, post: 4081663"] Hi, As a beginner in python and matplotlib I come here with a possibly naïve question. I need to write code for automation of bar-plots and pie-charts creation. I chose to use matplotlib which is well adapted for this purpose. Nevertheless, some of my charts are not very legible due to interferences between to many or to long labels. Sometimes my labels spread over the edge of the picture, and therefore are simply cut out; sometimes the different labels superpose, resulting in an illegible pie-chart. Do you know an easy way to control the labels size and repartition ? Is it possible to prohibit the label cutting, for instance a way to set the picture size so that no label is cut anymore ? Does matplotlib provide an easy way to spread labels or pie chunks so that the labels do not interfere with each other ? You will find my two code samples here after Any hint or recommendation appreciated --Ben # pie chart code # def savePie(populationGO,filepath,figtitle): """ saves Pie Charts of a population to a file """ plt.figure(figsize=(8,8)) labels=[k+"\n"+str(v) for k,v in populationGO.iteritems()] plt.clf(); plt.pie (populationGO.values(),labels=labels,labeldistance=1.1,autopct='%1.1f% %',pctdistance=.8) plt.title(figtitle) plt.savefig(filepath) # bar plot code # barPlotWidth=.25 plt.clf() barPlotOffsets = np.arange(len(labels)) r1 = plt.bar(barPlotOffsets ,popGO ,color="r",width=barPlotWidth) r2 = plt.bar(barPlotOffsets +barPlotWidth ,popGOall ,color="g",width=barPlotWidth) r3 = plt.bar(barPlotOffsets +(2*barPlotWidth) ,popGOlowr ,color="b",width=barPlotWidth) plt.ylabel('Population (number of protein chains)') plt.title('GO Population by simplified GO and dataset') plt.xticks(barPlotOffsets+barPlotWidth, labels,rotation = 17 ) plt.legend( (r1[0],r2[0],r3[0]), ("all SIFTS annotated","all PDB protein chains","all PDB p.chains R<=2.1") ) print "\nSave comparative bar plot file" fileName = "GO-population--comparative-bar-plot.png" print "...",fileName filepath=os.path.join(pc.resDir,fileName) plt.savefig(filepath) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
labels legibility in matplotlib pie charts and bar plots
Top