【问题标题】:python multiple stacked plots along y axispython沿y轴的多个堆叠图
【发布时间】:2017-11-15 00:12:38
【问题描述】:

我有一个 x 轴 n 长度向量和 3 个 y 轴 n 长度向量的分箱数据,用于同一 x 轴上的 3 个不同直方图。

现在我想要这种堆积条形图或类似下面的任何东西。

我找到的最近的是Qtiplot(不是python)。它可以准确地生成这种直方图。但它自己计算直方图,并需要我的案例中不存在的实际数据样本(我只有直方图本身)。

请注意,我不太了解python。所以我不知道从哪里开始,我也没有心情学习 Python 编程。我只需要这个来为我的研究论文制作一个漂亮的矢量图形图。

我标记了python,因为我认为 python 是最明显的语言。如果有人知道除 python 之外的任何更好的解决方案(但不是 Matlab,我无法安装那一大堆),谢天谢地,我会添加正确的标签。

提前感谢您的帮助。

【问题讨论】:

    标签: python plot visualization stacked


    【解决方案1】:

    在python中使用matplotlib包

    import matplotlib.pyplot as plt
    
    apple_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    banana_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    mango_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    
    fig=plt.figure()
    ax1=fig.add_subplot(311)
    ax2=fig.add_subplot(312)
    ax3=fig.add_subplot(313)
    ax1.hist(apple_weight)
    ax2.hist(banana_weight)
    ax3.hist(mango_weight)
    plt.show()
    

    【讨论】:

    • 谢谢!有没有办法可以共享y轴,特别是ylabel?
    • 而不是 ax2=add_subplot(312) 写 ax2=ax.twinx()
    【解决方案2】:
    import matplotlib.pyplot as plt
    
    apple_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    banana_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    mango_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
    
    fig=plt.figure()
    ax1=fig.add_subplot(111)
    ax2=ax1.twinx()
    #only two y axes so the third list just add to either
    
    ax1.hist(apple_weight)
    ax2.hist(banana_weight)
    ax1.hist(mango_weight)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 2012-11-30
      • 2021-07-22
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 2021-02-13
      • 1970-01-01
      相关资源
      最近更新 更多