饼图 - 如何仅表示列的一个值?

发布于 2025-02-13 00:00:21 字数 351 浏览 0 评论 0原文

目标 - 我们可以在饼图上仅表示一个值吗? 例如,我有一个名为“严重性”的列,总共有500个值,并包含多个值“ CAT 1”& “ CAT 2”和单个计数如下(CAT 1-484&和Cat2 -16)

我的问题是我可以在饼图上表示一个值吗? (即)仅具有475个值的CAT 1(请参阅下面的屏幕截图,以获取更多

”在此处输入图像说明”

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2025-02-20 00:00:21

如何在Matplotlib饼图中显示实际值a> - 我认为这有您想要的。

例如

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()

,IF语句当然可以与DF数据匹配。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文