matplotlib设置饼图的标签文字大小
可以使用matplotlib.pyplot.pie函数的textprops参数来设置饼图的标签文字大小,具体步骤如下:
- 创建饼图数据和标签文字:
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D', 'E']
sizes = [20, 30, 10, 15, 25]
- 设置标签文字大小,这里设置为14:
textprops = {'fontsize': 14}
- 调用
pyplot.pie函数绘制饼图,并传入textprops参数:
plt.pie(sizes, labels=labels, textprops=textprops)
完整代码:
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D', 'E']
sizes = [20, 30, 10, 15, 25]
textprops = {'fontsize': 14}
plt.pie(sizes, labels=labels, textprops=textprops)
plt.show()
``
原文地址: https://www.cveoy.top/t/topic/htCc 著作权归作者所有。请勿转载和采集!