【问题标题】:Why is the y axis in increments of 1 rather than 90为什么y轴的增量为1而不是90
【发布时间】:2020-03-26 19:16:47
【问题描述】:
我想制作一个正弦图,但 y 轴已关闭,我该如何更改。
还有 linspace 后面括号中的 3 个数字是什么意思?
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 7, 100)
y = np.sin(x)
plt.plot(x, y)
plt.grid(True)
plt.show()
谢谢
【问题讨论】:
标签:
python
matplotlib
graph
【解决方案1】:
请参阅set_xlim 以调整 x 轴的范围。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 7, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x,y)
ax.grid(True)
ax.set_xlim(0,7)
plt.show()
之前:
之后:
np.linspace 命令中的三个数字分别表示start、stop和num。 IE。它会生成一个由 0 到 7 之间的 100 个均匀间隔的数字组成的数组。