Are there anyway to specify the position of title in pie chart using matplotlib?

Viewed 2198

I don't know how to specify the position of the title using matplotlib. I want the title to be a bit more further away from the label but I don't know how to set it.

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

1 Answers

You can simply add a 'pad' argument to 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()

Increase or decrease the value to offset the title's y coordinate.

Related