错误:float()参数必须是字符串或数字,而不是“axesssubplot”

2024-06-16 13:47:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在pandaps中生成某些图的子图,但一直遇到这样的错误:float()参数必须是一个字符串或数字,而不是“AxesSubplot”有什么建议吗?在

colours = ['#F5DEB3', '#528B8B', '#9E9E9E', '#FFA500']

sex_and_wellbeing = results_redditThread_df.groupby(['pay_for_sex'])[['bodyweight']].apply(lambda x: pd.DataFrame(x['bodyweight'].value_counts()))

sex_and_wellbeing = sex_and_wellbeing.unstack()
graph_sex_and_wellbeing3 = sex_and_wellbeing.plot(kind='bar', figsize=(20, 13), color=colours, rot=0, fontsize=21)

graph_sex_and_wellbeing3.set_title('Number of People who would Pay for Sex based on Bodyweight', fontsize=24)
graph_sex_and_wellbeing3.set_xlabel('Sex payments', fontsize=21)
graph_sex_and_wellbeing3.set_ylabel('Number of People with Certain Weight', fontsize=21)
graph_sex_and_wellbeing3.legend(
    ['Normal Weight', 'Obese', 'Overweight', 'Underweight'],
   loc='best',
   ncol=1,
   markerscale=1.5,
   fontsize=15)

fig, ax = plt.subplots(2)
ax[0].plot(graph_sex_and_wellbeing)
ax[1].plot(graph_sex_and_wellbeing3)

Code preview here


Tags: andofnumberforplotaxpeoplegraph
1条回答
网友
1楼 · 发布于 2024-06-16 13:47:10

好吧,根据异常回溯,您试图将graph_sex_and_wellbeing转换为float。Python中的float可以接受字符串或数字参数。graph_sex_and_wellbeing具有类型AxesSubplot。您需要从这个变量中获取一个字符串或数字并将其传递给一个浮点。在

相关问题 更多 >