是否仍然可以使用matplotlib指定标题在饼图中的位置?

2024-04-16 08:18:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道如何使用matplotlib指定标题的位置。我希望标题离标签再远一点,但我不知道如何设置它

labels = df03['new_sentiment']
count = df03['count']

fig1, ax1 = plt.subplots()
ax1.pie(count, labels=labels, autopct='%1.1f%%')
ax1.axis('equal')
plt.title('7D-prior-3MD_sem_sen')
plt.savefig('04_7D-prior-3MD_sem_sen.tiff', dpi=300, format='tiff', bbox_inches='tight')

enter image description here


Tags: 标题newlabelsmatplotlibcountplt标签sentiment
1条回答
网友
1楼 · 发布于 2024-04-16 08:18:45

您只需将'pad'参数添加到plt.title():

import matplotlib.pyplot as plt
count = [3, 4, 5]
labels = ['Neutral', 'Negative', 'Positive']
fig1, ax1 = plt.subplots()
ax1.pie(count, labels=labels, autopct='%1.1f%%')
ax1.axis('equal')
plt.title('7D-prior-3MD_sem_sen', pad=32)
plt.show()

增加或减少该值以偏移标题的y坐标

相关问题 更多 >