【问题标题】:Plot histograms of 2 different dataframes with the same columns绘制具有相同列的 2 个不同数据帧的直方图
【发布时间】:2022-03-11 08:30:42
【问题描述】:

我有 2 个名为 df1 和 df2 的数据框,它们具有相同的 15 列。假设 df1 有 A、B、C 列,而 df1 也有 A、B、C 列。我想使用.hist(),以便我有 15 个图,每个图由 2 个直方图组成(即图 1 具有来自 DF1 的 A 列和来自 df2 的 A 列的直方图)。我希望这两个数据框的图具有与我尝试另一种方法相同的比例,最终得到不规则的 x 轴。

   df1 =  A B C
        1 . . .
        2 . . .
        3 . . .
   df2 =  A B C
        1 * * *
        2 * * *
        3 * * *
#Plot 1 should have column A from df1 and column A from df2.
#Plot 1 should have column B from df1 and column B from df2.
# and so on.

[我尝试制作单个图形代码,所以这是输出。]https://i.stack.imgur.com/w5wSM.png

【问题讨论】:

    标签: python dataframe matplotlib plot


    【解决方案1】:

    确定您需要的垃圾箱:

    a = np.linspace(start, stop, nbins)
    hist1 = np.histogram(df1.A, bins=a)
    hist2 = np.histogram(df2.A, bins=a)
    

    这里的“a”是直方图用来制作分箱的序列

    https://numpy.org/doc/stable/reference/generated/numpy.histogram.html

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 2019-03-08
      • 1970-01-01
      相关资源
      最近更新 更多