如何创建一个直方图,可以显示有关TimeToPayInDays的年龄?
我在文档中看不到y轴的任何y
参数。
我想看看年龄是否会影响还款时间。
#check if age influences how fast men pay what they owe to bank
print(malesSample['Age'].min())
print(malesSample['Age'].max())
# Creating histogram
fig, ax = plt.subplots(figsize =(10, 7))
ax.hist(malesSample['Age'], bins = malesSample['TimeToPayInDays'])
# Show plot
plt.show()
**csv DataSet**
Age TimeToPayInDays
22 4
24 5
39 64
17 27
36 12
51 85
42 19
修改
按照谢尔盖的建议,我做了一个散点图。
print(malesSample['Age'].min()) #21.0
print(malesSample['Age'].max()) #51.0
print(feamalesSample['Age'].min()) #23.0
print(feamalesSample['Age'].max()) #44.0
age_Range = [20,25,30,35,40,45,50,55]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.scatter(x=malesSample['Paid_Off_In_Days'],y=malesSample['Age'], color='blue')
ax.set_xlabel('Paid Off In_Days')
ax.set_ylabel('Age')
ax.set_title('How does age influences time to pay off loan?')
plt.show()