0

Goal - Can we represent just one value on the pie chart? For example, I have a column titled 'Severity' and it has 500 values in total and contains multiple values 'CAT 1' & 'CAT 2' and individual count are as follows (CAT 1 - 484 & and CAT2 -16)

My question is can I represent on PIE chart just one value? (i.e) only CAT 1 which has 475 values (please see the below screenshot attached for more

enter image description here

martineau
  • 119,623
  • 25
  • 170
  • 301
skumar
  • 99
  • 1
  • 11
  • 1
    [Please do not upload images of code/data/errors when asking a question.](http://meta.stackoverflow.com/q/285551) – martineau Jul 05 '22 at 13:51

1 Answers1

0

How to have actual values in matplotlib Pie Chart displayed - I think this has what you are looking for.

e.g.

import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame()
df["Severity_Values"] = ["CAT1","CAT2"]
df["counts"] = [484,16]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.axis('equal')


p, tx, autotexts = ax.pie(df.counts,radius=1.8,labels=df.Severity_Values,autopct='%1.2f%%',textprops={'fontsize':14},data='Text')
for i, a in enumerate(autotexts):
    if i == 0:
        a.set_text(f"Changed Text \n{a.get_text()}")
    else:
        a.set_text("")

for i, a in enumerate(tx):
    if i == 0:
        a.set_text(f"Changed Text \n{a.get_text()}")
    else:
        a.set_text("")
        
plt.show()

Of course the if statement could be conditional on a match with df data.