![](/img/trans.png)
[英]Python how to plot a frequency pie chart with one column using plotly.express
[英]Pie chart - How to represent just one value of a column?
如何在 matplotlib 饼图中显示实际值- 我认为这就是您想要的。
例如
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 数据为条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.