[英]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.