matplotlib This is your own way to draw pie charts neatly. If you write the following data that needs various adjustments in a pie chart, it will be troublesome to adjust each time.
――The label is long or short. --There are 10 or more data, or 1 data.
code
# coding:utf-8
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
###data###
data=[1011,530,355,200,40,11]
label=['hoge','fuga','piyo','pugya','dododododododo','ga']
###Magic to write beautifully###
plt.style.use('ggplot')
plt.rcParams.update({'font.size':15})
###Various parameters###
size=(9,5) #Keep size horizontally long because of the placement of the legend.
col=cm.Spectral(np.arange(len(data))/float(len(data))) #Select the color you like from the color map.
###pie###
plt.figure(figsize=size,dpi=100)
plt.pie(data,colors=col,counterclock=False,startangle=90,autopct=lambda p:'{:.1f}%'.format(p) if p>=5 else '')
plt.subplots_adjust(left=0,right=0.7)
plt.legend(label,fancybox=True,loc='center left',bbox_to_anchor=(0.9,0.5))
plt.axis('equal')
plt.savefig('figure.png',bbox_inches='tight',pad_inches=0.05)
It looks like this with only plt.pie (data),
I feel like this.
Colormap is your favorite from the following site. http://matplotlib.org/examples/color/colormaps_reference.html Various options http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.pie
http://d.hatena.ne.jp/a-hisame/20150424/1429875458
Recommended Posts