【问题标题】:Plotting two lists with different lengths with interpolation用插值绘制两个不同长度的列表
【发布时间】:2013-07-18 16:00:04
【问题描述】:

我需要绘制两个数字列表,但我需要扩展两者的范围。

第一个列表包含事情发生的次数(我正在模拟)。第二个包含累积频率。两者的一个例子是:

number_of_times = [77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90]
cumsum = [0.01, 0.02, 0.03, 0.04, 0.09, 0.16, 0.3, 0.46, 0.74, 0.89, 0.95, 0.99, 1.0]

如何将它们相互绘制,x 轴 (numvber_of_times) 的范围为 0-100,但要确保累积频率仍然匹配?

目前我正在使用

plt.plot(num.keys(), cumsum)
plt.show()

但这看起来不太好。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您当前正在尝试根据列表 cumsum 绘制字典 num 的键。只需将两个列表作为参数提供给 plot 方法,然后使用 xlim 设置 x 限制。

    number_of_times = [77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90]
    cumsum = [0.01, 0.02, 0.03, 0.04, 0.09, 0.16, 0.3, 0.46, 0.74, 0.89, 0.95, 0.99, 1.0]
    
    plt.plot(number_of_times, cumsum)
    plt.xlim(0, 100)
    
    plt.show()
    

    【讨论】:

    • 谢谢!我不知道你可以设置限制!
    猜你喜欢
    • 2019-06-30
    • 2015-09-09
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 2017-10-15
    • 2021-02-25
    • 1970-01-01
    相关资源
    最近更新 更多