import numpy as np
import matplotlib.pyplot as plt
# 不用打imshow也能显示
%matplotlib inline
饼图
m = 51212
f = 40742
m_perc = m/(m+f)
f_perc = f/(m+f)
colors = ['navy','lightcoral']
labels = ['Male','Female']
plt.figure(figsize=(12,12))
# autopct 显示百分比的设置, expolde 两半个圆的距离
patches, texts, autotexts = plt.pie([m_perc,f_perc],labels=labels, autopct='%1.1f%%', explode=[0,0.05], colors=colors)
m = 51212
f = 40742
m_perc = m/(m+f)
f_perc = f/(m+f)
colors = ['navy','lightcoral']
labels = ['Male','Female']
plt.figure(figsize=(12,12))
# autopct 显示百分比的设置, expolde 两半个圆的距离
patches, 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')