Reputation: 4406
I have this code and the expected output is (see first picture) but the actually output is (see 2nd picture). What is going wrong?
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(-.75, 2.25, .001)
p = 1 / (np.cos(t) + np.sin(t))
plt.plot(p)
plt.axis((-1, 2.5, 0, 4))
plt.show()
Upvotes: 1
Views: 152
Reputation: 2553
This should fix it:
plt.plot(t, p)
What you were doing was plotting p
against range(len(p))
, essentially.
Upvotes: 4