【问题标题】:Fill data between points Matplotlib [closed]在点之间填充数据 Matplotlib [关闭]
【发布时间】:2020-05-12 11:09:37
【问题描述】:

我从 Matplotlib 开始,我需要重新创建一个 X 从 1 到 28 的图形。 图文:

我怎样才能只用 6 个值来做这个图形,并填充它们之间的值?

【问题讨论】:

    标签: python python-3.x numpy matplotlib


    【解决方案1】:

    请在xy中插入“精确”值

    import matplotlib.pyplot as plt
    
    # data, the length of the two lists MUST be the same 
    x = [0, 6, 10, 15, 17, 26, 28] 
    y = [0, 20, 20, 30, 30, 0, 0] 
    
    # plot the data
    plt.plot(x,y) 
    
    # modify the ticks to show directly the values
    plt.xticks(x) 
    plt.yticks(sorted(set(y))) 
    
    # make a grid
    plt.grid(1)
    
    # tell matplotlib "we are done, please show what we have prepared"
    plt.show()                                                                    
    

    【讨论】:

      【解决方案2】:

      很难从图像中读取准确值;您必须自己输入正确的值。如果您有任何问题,请随时提出。

      import matplotlib.pyplot as plt
      
      x = [0, 6, 10, 15, 22, 26]
      y = [0, 22, 22, 27.5, 27.5, 0]
      
      # optional; making the y axis go up to 45
      axes = plt.gca()
      axes.set_ylim([0, 45])
      
      plt.plot(x,y)
      plt.show()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-28
        • 2018-11-03
        • 2020-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-28
        相关资源
        最近更新 更多