【问题标题】:Set 'sharex' argument to 'axes1' and 'sharey' argument to 'axes1'将“sharex”参数设置为“axes1”,将“sharey”参数设置为“axes1”
【发布时间】:2019-06-18 16:35:21
【问题描述】:

用表达式'np.arange(0.0, 5.0, 0.01)'定义一个numpy数组't'。

用表达式'np.sin(2np.pit)'定义另一个numpy数组's1'

用表达式“np.sin(4np.pit)”再定义一个 numpy 数组“s2”。

创建一个宽 8 英寸,高 6 英寸的图形。将其命名为图。

使用 plt.subplot 函数创建一个坐标区。将其命名为轴 1。子图必须指向由 2 行和 1 列创建的第一个虚拟网格。将“title”参数设置为“Sin(2pix)”。

在'axes1`上使用'plot'函数绘制't'和's1'的线图。

使用 plt.subplot 函数创建另一个坐标区。将其命名为轴 2。子图必须指向由 2 行和 1 列创建的第二个虚拟网格。将“title”参数设置为“Sin(4pix)”。 将“sharex”参数设置为“axes1”,将“sharey”参数设置为“axes1”。

使用'axes2`上的'plot'函数绘制't'和's2'的线图。

第 2 和第 3 功能的说明分别在步骤 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”。

【问题讨论】:

    标签: matplotlib scatter-plot


    【解决方案1】:

    您可以在创建axes2 时指定要共享的轴,如下所示。其余代码保持不变

    axes2 = plt.subplot(2, 1, 2, title='Sin(4pix)', sharex=axes1, sharey=axes1)
    

    【讨论】:

    • meta上有一些关于回答作业问题的帖子,您可能想阅读一下。
    • @ImportanceOfBeingErnest :我回答是因为 OP 包含可重现的代码。我完全同意问题的构成方式,它显然是一项家庭作业。下次我会记住你的话:)
    猜你喜欢
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 2019-07-07
    • 2014-08-23
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多