Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Different values in matplotlib piechart from the pandas dataframe

Check this code:

import matplotlib.pyplot as plt
import pandas as pd

data = {
    'Região': ['NORTE', 'SUDESTE', 'NORDESTE', 'CENTRO OESTE', 'SUL'],
    'PNT "Real" sobre mercado BT (%)': [52.75, 15.04, 12.82, 8.23, 8.04]
}
data = pd.DataFrame(data)
data.set_index('Região', inplace=True)

plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
ax.patch.set_edgecolor('black')  
ax.patch.set_linewidth(1) 
ax.pie(data['PNT "Real" sobre mercado BT (%)'].values, textprops={'size': 'smaller'}, labels=data.index, autopct='%1.2f%%', wedgeprops={'edgecolor':'black'})
ax.axis('equal')
# fig.savefig('pnts_sobre_BT_Regioes.png', dpi=300)
plt.show()

I am getting this figure as result:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why are the values in the figure different from the ondes in data?

>Solution :

Because your data do not add up to 100 %. The keyword autopct means that percentages are calculated with respect to the sum of your data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading