1

我有这段代码,预期的输出是(见第一张图),但实际输出是(见第二张图)。出了什么问题?

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

正确的输出

错误的输出

4

1 回答 1

4

This should fix it:

plt.plot(t, p)

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

于 2013-04-11T00:22:30.633 回答