将 'sharex' 参数设置为 'axes1' 并将 'sharey' 参数设置为 'axes1'
Set 'sharex' argument to 'axes1' and 'sharey' argument to 'axes1'
用表达式 'np.arange(0.0, 5.0, 0.01)'.
定义一个 numpy 数组 't'
用表达式 'np.sin(2np.pit)'
定义另一个 numpy 数组 's1'
用表达式 'np.sin(4np.pit)'.
再定义一个 numpy 数组 's2'
创建一个宽 8 英寸、高 6 英寸的图形。命名为fig.
创建一个轴,使用 plt.subplot 函数。将其命名为 axes1。子图必须指向由 2 行和 1 列创建的第一个虚拟网格。将 'title' 参数设置为 'Sin(2pix)'.
使用“axes1”上的 'plot' 函数绘制 't' 和 's1' 的线图。
创建另一个轴,使用 plt.subplot 函数。将其命名为 axes2。子图必须指向由 2 行和 1 列创建的第二个虚拟网格。将 'title' 参数设置为 'Sin(4pix)'。
将 'sharex' 参数设置为 'axes1' 并将 'sharey' 参数设置为 'axes1'.
使用“axes2”上的 'plot' 函数绘制 't' 和 's2' 的线图。
第二个和第三个功能的说明分别在步骤 3、4 和 5 中提供。请保存您的代码并继续下一步。
import numpy as np
fig = plt.figure(figsize=(8,6))
axes1 = plt.subplot(2, 1, 1, title='Sin(2pix)')
axes2 = plt.subplot(2, 1, 2, title='Sin(4pix)')
t = np.arange(0.0, 5.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)
axes1.plot(t, s1)
axes2.plot(t, s2)
如何设置:将 'sharex' 参数设置为 'axes1',将 'sharey' 参数设置为 'axes1'。
您可以在创建 axes2
时指定要共享的轴,如下所示。其余代码保持不变
axes2 = plt.subplot(2, 1, 2, title='Sin(4pix)', sharex=axes1, sharey=axes1)
用表达式 'np.arange(0.0, 5.0, 0.01)'.
定义一个 numpy 数组 't'用表达式 'np.sin(2np.pit)'
定义另一个 numpy 数组 's1'用表达式 'np.sin(4np.pit)'.
再定义一个 numpy 数组 's2'创建一个宽 8 英寸、高 6 英寸的图形。命名为fig.
创建一个轴,使用 plt.subplot 函数。将其命名为 axes1。子图必须指向由 2 行和 1 列创建的第一个虚拟网格。将 'title' 参数设置为 'Sin(2pix)'.
使用“axes1”上的 'plot' 函数绘制 't' 和 's1' 的线图。
创建另一个轴,使用 plt.subplot 函数。将其命名为 axes2。子图必须指向由 2 行和 1 列创建的第二个虚拟网格。将 'title' 参数设置为 'Sin(4pix)'。 将 'sharex' 参数设置为 'axes1' 并将 'sharey' 参数设置为 'axes1'.
使用“axes2”上的 'plot' 函数绘制 't' 和 's2' 的线图。
第二个和第三个功能的说明分别在步骤 3、4 和 5 中提供。请保存您的代码并继续下一步。
import numpy as np
fig = plt.figure(figsize=(8,6))
axes1 = plt.subplot(2, 1, 1, title='Sin(2pix)')
axes2 = plt.subplot(2, 1, 2, title='Sin(4pix)')
t = np.arange(0.0, 5.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)
axes1.plot(t, s1)
axes2.plot(t, s2)
如何设置:将 'sharex' 参数设置为 'axes1',将 'sharey' 参数设置为 'axes1'。
您可以在创建 axes2
时指定要共享的轴,如下所示。其余代码保持不变
axes2 = plt.subplot(2, 1, 2, title='Sin(4pix)', sharex=axes1, sharey=axes1)