dustin
dustin

Reputation: 4406

python plot isn't turning out correctly

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

Correct output

Wrong output

Upvotes: 1

Views: 152

Answers (1)

Sajjan Singh
Sajjan Singh

Reputation: 2553

This should fix it:

plt.plot(t, p)

What you were doing was plotting p against range(len(p)), essentially.

Upvotes: 4

Related Questions