子图中的轴限制

Axis Limits in Subplots

我正在尝试操纵 python 中子图的轴限制。无论我在哪里尝试放置 axes-command,似乎总是有另一个问题。我想创建一个子图并单独操作轴限制。在我的情节中没有设置限制 window 或子情节完全消失。

我的代码:

"Import"
import numpy as np
import matplotlib.pyplot as plt

"Maths"
x = np.linspace(-10,10,1000)
b = [2,3,4]
f = 3 #in Hz

def y(z):
    return(np.sin(2*np.pi*f*x) * np.sin(2*np.pi*b[z]*x))

"Plot"
plt.close("all")
%matplotlib inline
plt.figure(figsize = (12,10))

plt.axes(xlim=(-5,5), ylim=(-1,1))

plt.subplot(3,1,1)
plt.plot(x,y(0))
plt.grid()
    
plt.subplot(3,1,2)
plt.plot(x,y(1))
plt.grid()

plt.subplot(3,1,3)
plt.plot(x,y(2))
plt.grid()

试试这些。它必须放在每个 plt.subplot() 命令之后。 通常您会在 plt.plot() 命令之后看到这些命令。

plt.xlim((left, right))
plt.ylim((bottom, top))