Pythonはレインボー円グラフを描画します



Python Draws Rainbow Pie Chart



from matplotlib import font_manager as fm from matplotlib import cm import matplotlib.pyplot as plt import pandas as pd import numpy as np shapes = ['Cross', 'Cone', 'Egg', 'Teardrop', 'Chevron', 'Diamond', 'Cylinder', 'Rectangle', 'Flash', 'Cigar', 'Changing', 'Formation'] values = [287, 383, 842, 866, 1187, 1405, 1495, 1620, 1717, 2313, 2378, 3070] s = pd.Series(values, index=shapes) labels = s.index sizes = s.values # explode = (0.2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) # only 'explode' the 1st slice fig, axes = plt.subplots(figsize=(10,5),ncols=2) # Set the drawing area size ax1, ax2 = axes.ravel() colors = cm.rainbow(np.arange(len(sizes))/len(sizes)) # colormaps: Paired, autumn, rainbow, gray,spring,Darks patches, texts, autotexts = ax1.pie(sizes, labels=labels, autopct='%1.0f%%', shadow=False, startangle=170, colors=colors) ax1.axis('equal') # Reset font size proptease = fm.FontProperties() proptease.set_size('xx-small') # font size include: ‘xx-small’,x-small’,'small’,'medium’,‘large’,‘x-large’,‘xx-large’ or number, e.g. '12' plt.setp(autotexts, fontproperties=proptease) plt.setp(texts, fontproperties=proptease) ax1.set_title('Shapes', loc='center') # ax2 Only show the legend (legend) ax2.axis('off') ax2.legend(patches, labels, loc='center left') plt.tight_layout() plt.savefig('Demo_project_set_legend_good.jpg') plt.show()

操作効果は以下のとおりです。
画像