这是我的代码:
import numpy as np
import matplotlib.pyplot as plt
data = np.genfromtxt("C:\\Users\\pearl\\Downloads\\Age group.csv",
delimiter=',',
names=True, dtype=('U7','U40','U13',int))
x= ['15-19','20-24', '25-29','30-34','35-39','40-44']
y = data[data['birth_type'] == 'Single Birth']['total_number_of_mother']
plt.hist(x,y)
plt.show()但是,我得到一个值错误,说bins必须单调增加。我能得到一些帮助吗?
发布于 2021-09-10 22:14:00
我知道很晚了,但试试这个:
import numpy as np
import matplotlib.pyplot as plt
data = np.genfromtxt("C:\\Users\\pearl\\Downloads\\Age group.csv",
delimiter=',',
names=True, dtype=('U7','U40','U13',int))
x= ['15-19','20-24', '25-29','30-34','35-39','40-44']
y = data[data['birth_type'] == 'Single Birth']['total_number_of_mother']
plt.hist([x,y]) # ADD BRACKETS AROUND THIS.
plt.show()plt.hist()的第二个参数是存储箱,您的代码被解释为将存储箱解释为"y“。
https://stackoverflow.com/questions/65263726
复制相似问题