Reputation: 381
I want to plot the following
from matplotlib import pyplot as plt
import numpy as np
N = 1000000
for k in range(1, 2000):
plt.plot(k, 1 - np.exp(-0.5 * k * (k - 1) / N))
plt.show()
But there output is just the axis
Why is that?
Upvotes: 0
Views: 51
Reputation: 31153
What exactly do you want to have as a result? Currently your code does 2000 plots and by default they don't show anything since each has only one point and default is a line graph. If you want to plot a single line graph from 1 to 2000 then you should use this:
from matplotlib import pyplot as plt
import numpy as np
N = 1000000
plt.plot(range(1, 2000), [1 - np.exp(-0.5 * k * (k - 1) / N) for k in range(1, 2000)])
plt.show()
It creates a single plot with x going from 1 to 2000 and y getting values with the formula also from 1 to 2000.
If you do want 2000 separate plots then you can define the style for plot()
, for example 's'
as the last parameter, or if you want a single color for each point you can add that too, for example 'ks'
for black.
Upvotes: 0
Reputation: 3121
You're not showing anything in the plot because of you didn't set any color parameter. Set a color parameter and you will the output. For demonstration I set a blue color code.
plt.plot(k, 1 - np.exp(-0.5 * k * (k - 1) / N), 'bs')
Upvotes: 1