Reputation: 2669
I need to plot two lists of numbers against each other, but I need to extend the range of both.
The first list contains the number of time a thing happens (which I'm simulating). The second contains the cumulative frequency. An example of both is:
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]
How can I plot these against each other, with the x-axis (numvber_of_times) having a range of 0-100, but making sure that the cumulative frequency still matches up?
Currently I'm using
plt.plot(num.keys(), cumsum)
plt.show()
but this just doesn't look that good.
Upvotes: 1
Views: 848
Reputation: 12933
You are currently trying to plot the keys of a dictionary num
against the list cumsum
. Simply feed the plot
method the two lists as arguments, and set the x-limits with xlim
.
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()
Upvotes: 1