【问题标题】:Plot two histograms from DataFrame on the same graph, specifieng axises在同一个图上绘制来自 DataFrame 的两个直方图,指定轴
【发布时间】:2017-03-28 18:10:47
【问题描述】:

我有一个 DataFrame df

    A           B
H   
8   0.899160    1
9   41.659693   7
10  336.414450  20
11  8.442857    3
12  0.848837    1
13  3.298130    2
14  3.447251    2
15  7.667236    3
17  0.831579    1
16  0.000000    0

我想在一个图上绘制 2 个直方图,所以 H - 是 x 轴,AB - y 轴。 无论我尝试什么,例如:

x = delivered['A']
y = delivered['B']
fig = plt.figure()
ax = fig.add_subplot(111)
x.plot(kind='hist', ax=ax)
y.plot(kind='hist', ax=ax, color='red')

p = df.plot(kind='hist', x=['H'])

B 为 x 轴绘制直方图。但我需要我的 H{8,9,10,11,12,13,14,15,16,17} 作为 x 轴!

【问题讨论】:

标签: python pandas plot


【解决方案1】:

正如@jrjc 所说,问题在于我选择了错误的图表类型!。因为我已经计算了每个观察的特征,所以需要“条形”图。 “hist”图适用于每个观察都有大量行的情况。

【讨论】:

    猜你喜欢
    • 2019-01-15
    • 2015-01-10
    • 2015-04-04
    • 1970-01-01
    • 2016-01-02
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多