[英]Error: float() argument must be a string or a number, not 'AxesSubplot'
我試圖在某些圖形的熊貓中進行子圖繪制,但我不斷收到此錯誤: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
。 您需要從此變量獲取字符串或數字,並將其傳遞給浮點數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.