Search code examples
pythonpandasplotpie-chart

How can I adjust width and height in Pandas graph?


I have a problem about showing image in terms of width and height. Some parts of it cannot be shown in png file.(Especially right side , some text cannot be shown) How can I fix it?.

enter image description here

Here is my code shown below.

plt.figure(figsize=(10,9))
ax = subplot_kw=dict(aspect="equal")
my_circle = plt.Circle((0, 0), 0.7, color='white')


d = plt.pie(symptoms['percentage'],
            autopct='%1.1f%%',
            pctdistance=0.85, 
            labeldistance=1.1,
            textprops = {'fontsize':10.5})

plt.axis('equal')
plt.gca().add_artist(my_circle)

plt.text(0, 
         0, 
         "Symptoms of Coronavirus",
         horizontalalignment='center',
         verticalalignment='center',
         size=16,
        )

plt.legend(symptoms['symptom'],loc='right',bbox_to_anchor=[1.2, 0.5])
plt.savefig('images/image2.png')
plt.savefig('images/image2.pdf')  
plt.show()

Solution

  • I solved the issue by writing this code shown below.

    .....
    plt.tight_layout()
    plt.show()