我试图在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)
好吧,根据异常回溯,您试图将
graph_sex_and_wellbeing
转换为float
。Python中的float
可以接受字符串或数字参数。graph_sex_and_wellbeing
具有类型AxesSubplot
。您需要从这个变量中获取一个字符串或数字并将其传递给一个浮点。在相关问题 更多 >
编程相关推荐