简体   繁体   English

python情节不正确

[英]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). 我有这个代码和预期的输出(见第一张图片)但实际输出是(见第2张图片)。 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()

正确的输出

输出错误

This should fix it: 这应该解决它:

plt.plot(t, p)

What you were doing was plotting p against range(len(p)) , essentially. 你正在做的是绘制prange(len(p)) ,基本上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM