matplotlib中的pie圖

餅圖

  • 設置顏色
  • 設置字體顏色
  • 設置說明文字
%matplotlib inline
import matplotlib.pyplot as plt

m = 51212
f = 40742
m_perc = m/(m+f)
f_perc = f/(m+f)

colors = ['navy','lightcoral']
labels = ["Male","Female"]

plt.figure(figsize=(8,8))
paches,texts,autotexts = plt.pie([m_perc, f_perc], labels = labels,
				autopct = '%1.1f%%', explode = [0,0.05], colors = colors)

for text in texts+autotexts:
    text.set_fontsize(20)
for text in autotexts:
    text.set_color('white')

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章