Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何[绘出]更改此饼图中的标签?_Python_Plotly_Plotly Python - Fatal编程技术网

Python 如何[绘出]更改此饼图中的标签?

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

我想改变饼图上的标签[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
%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")