Python 如何[绘出]更改此饼图中的标签?
我想改变饼图上的标签[2,3,4,5],让它们分别写上[Boomer,Gen X,Gen Y,Gen Z]。在不改变数据帧的情况下,我似乎找不到一种直接的方法来实现这一点。有没有办法通过我的代码来做到这一点Python 如何[绘出]更改此饼图中的标签?,python,plotly,plotly-python,Python,Plotly,Plotly Python,我想改变饼图上的标签[2,3,4,5],让它们分别写上[Boomer,Gen X,Gen Y,Gen Z]。在不改变数据帧的情况下,我似乎找不到一种直接的方法来实现这一点。有没有办法通过我的代码来做到这一点 我不知道您的数据的数据结构,所以我制作了一个示例数据并创建了一个饼图。请修改您的代码以遵循此操作 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns %mat
我不知道您的数据的数据结构,所以我制作了一个示例数据并创建了一个饼图。请修改您的代码以遵循此操作
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# data = df.groupby("Q10_Ans")["Q4_Agree"].count()
data = pd.DataFrame({'Q10_Ans':['Boomer','Gen X','Gen Y','Gen Z'],'Q4_Agree':[2,3,4,5]})
fig, ax = plt.subplots(figsize=[10,6])
labels = data['Q10_Ans']
ax.pie(x=data['Q4_Agree'], autopct="%.1f%%", explode=[0.05]*4, labels=labels, pctdistance=0.5)
ax.set_title("Generations that agree data visualization will help with job prospects", fontsize=14);
plt.savefig("DeliveryPieChart.png")
更改代码怎么样 labels=data.keys 到 标签=[‘婴儿潮’、‘X代’、‘Y代’、‘Z代’]
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# data = df.groupby("Q10_Ans")["Q4_Agree"].count()
data = pd.DataFrame({'Q10_Ans':['Boomer','Gen X','Gen Y','Gen Z'],'Q4_Agree':[2,3,4,5]})
fig, ax = plt.subplots(figsize=[10,6])
labels = data['Q10_Ans']
ax.pie(x=data['Q4_Agree'], autopct="%.1f%%", explode=[0.05]*4, labels=labels, pctdistance=0.5)
ax.set_title("Generations that agree data visualization will help with job prospects", fontsize=14);
plt.savefig("DeliveryPieChart.png")