【发布时间】:2017-08-15 15:57:48
【问题描述】:
我想用 pandas 数据框绘制直方图。我的数据框中有四列,但我想选择其中两列并绘制它。我插入 xaxis 和 yaxis 值并绘制三个子直方图。
我的代码如下所示:
fig = plt.figure(figsize=(9,7), dpi=100)
h = plt.hist(x=df_mean_h ['id'], y=df_mean_h ['mean'],
color='red', label='h')
c = plt.hist(x=df_mean_c ['id'], y=df_mean_c ['mean'],
color='blue', label='c')
o = plt.hist( x=df_mean_o['id'], y=df_mean_o ['mean'],
color='green', label='o')
plt.show()
当我尝试查看直方图时,屏幕上什么也没有显示。我应该如何修复我的代码?
【问题讨论】:
-
我只能猜到:
plt.show()?或者,您可以使用DataFrame.plot.hist(by=None, bins=10, **kwds)请参阅pandas.pydata.org/pandas-docs/stable/generated/… -
我添加了
plt.show(),但它抛出了一个错误说ValueError: setting an array element with a sequence. -
您的错误可能源于您没有将数组传递给绘图而是一个熊猫对象。查看
df_mean_o['id']和df_mean_o['id'].values之间的区别