E.B*_*ach 5 python matplotlib pie-chart
我有一个饼形图,标题左对齐:
import matplotlib.pyplot as plt
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
sizes = [15, 30, 45, 10]
fig1, ax1 = plt.subplots()
ax1.pie(sizes, autopct='%1.1f%%', startangle=90)
ax1.axis('equal')
ax1.set_title('Pie Title', loc='left')
plt.tight_layout()
plt.savefig(r'C:\images\pie.png', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
这段代码产生了这张图片:
但是饼图周围有太多空白。我怎样才能使标题和饼图对齐,并裁掉不必要的空格?
我认为除了居中、向左或向右之外,您不能以其他方式移动 set_title 。您可以做的是添加如下文本:
ax1.text(-0.8, 1, 'Pie Title')
Run Code Online (Sandbox Code Playgroud)
有关如何更改字体等信息,请参阅此处的文档:http://matplotlib.org/users/text_props.html
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |