用插值绘制两个不同长度的列表

时间:2013-07-18 16:00:05

标签: python matplotlib

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

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

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()

但这看起来不太好。

1 个答案:

答案 0 :(得分:1)

您目前正在尝试针对列表num绘制字典cumsum的键。只需将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()

enter image description here