【发布时间】:2020-07-14 12:11:21
【问题描述】:
我的条形图有什么问题?
当我在这个 y 轴上使用变量名时,条形图不显示y = [totalMales, totalFemales] # if I input numerical values it works, but it doesn't with variable names
#check total number of males
totalMales = newDF.loc[(newDF.Gender=='Male')].count #409
print("totalMales" + str(totalMales))
totalFemales = newDF.loc[(newDF.Gender=='Female')].count() #77
print("totalFemales" + str(totalFemales))
#males are more likely to borrow than females 409 > 77
plt.style.use('ggplot')
x = ['Males', 'Females']
y = [totalMales, totalFemales] # if I input numerical values it works, but it doesn't with variable names
x_pos = [i for i, _ in enumerate(x)]
plt.bar(x_pos, y, color='green')
plt.xlabel("Gender")
plt.ylabel("Total who Paid Off")
plt.title("Number of Males vs Females who Paid Off")
plt.xticks(x_pos, x)
plt.show()
【问题讨论】:
标签: python-3.x pandas matplotlib