Skip to content

Instantly share code, notes, and snippets.

@mkacky
Created September 28, 2014 05:58
Show Gist options
  • Save mkacky/c2dc7c9934f7cc267e81 to your computer and use it in GitHub Desktop.
Save mkacky/c2dc7c9934f7cc267e81 to your computer and use it in GitHub Desktop.
#! /usr/local/bin/python2.7
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
# 全体のフォントサイズを設定
plt.rcParams.update({'font.size':20})
# 適当なデータ
data = [100, 65, 28, 5]
label = ["data1", "data2", "data3", "data4"]
color=("red", "blue", "green", "darkorange")
# アスペクト比を補正しないと,楕円のグラフになってしまう
plt.axis('equal')
plt.pie(data,
autopct='%1.1f%%', # グラフ中に割合を表示
pctdistance=0.6, # 割合の位置を指定 0が中心, 1が外周
startangle=90, # グラフの開始位置を12時の位置に変更
labels=label,
labeldistance=1.1, # ラベルの位置を指定
colors=color
)
# axesの大きさを[0,0,1,1]としたときの相対座標
lgnd=plt.legend(bbox_to_anchor=(1.0, 0.25, 1.55, 0.5), loc="center left", borderaxespad=0.)
plt.savefig("pie.png", bbox_extra_artists=(lgnd,), bbox_inches="tight")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment