0

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

enter image description here

Why is that?

2 Answers 2

1

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.