【问题标题】:Bar graph in python for 3 datasetspython中3个数据集的条形图
【发布时间】:2020-05-06 18:02:22
【问题描述】:

我有 3 个数据集。我想绘制他们的图表。

width=0.25
d1=[9.31,8.0,9.9,9.1]
plt.xticks(x,['3','5','9','11'])
plt.bar(x,d1,-width,align='edge')



d2=[10.31,11.0,12.9,19.1]
plt.xticks(x,['3','5','9','11'])
plt.bar(x,d2,+width,align='edge')

d3=[8.31,10.0,11.9,13.1]
plt.xticks(x,['3','5','9','11'])
plt.bar(x,d3,width,align='edge')

我有 3 个图例 d1d2d3。我怎样才能把它画成相等...

我没有得到准确的条形图。

【问题讨论】:

    标签: python-3.x matplotlib graph


    【解决方案1】:

    好的,我明白你的意思。您想在同一个 x 点上绘制三个不同的图形。

    
    import matplotlib.pyplot as plt
    
    width=0.25
    x = [1,2,3,4]
    d1=[9.31,8.0,9.9,9.1]
    d2=[10.31,11.0,12.9,19.1]
    d3=[8.31,10.0,11.9,13.1]
    
    def plot3graphs(x, d1, d2, d3, width):
    
        plt.xticks(x,['3','5','9','11'])
    
        x1 = [e-1.5*width for e in x]
        plt.bar(x1,d1,width,align='edge')
    
        x2 = [e-0.5*width for e in x]
        plt.bar(x2,d2,width,align='edge')
    
        x3 = [e+0.5* width for e in x]
        plt.bar(x3,d3,width,align='edge')
    
    
    plot3graphs(x, d1, d2, d3, width)
    plt.show()
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多