Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib 子批的返回值_Matplotlib_Python 2.6 - Fatal编程技术网

Matplotlib 子批的返回值

Matplotlib 子批的返回值,matplotlib,python-2.6,Matplotlib,Python 2.6,目前,我正在尝试熟悉matplotlib.pyplot库。在看过很多示例和教程之后,我注意到subplot函数也有一些返回值,这些值通常在以后使用。然而,在matplotlib网站上,我找不到关于返回内容的任何规范,并且没有一个示例是相同的(尽管它通常看起来是一个ax对象)。你们能给我一些关于返回什么以及我如何使用它的指示吗。提前谢谢 中,它表示matplotlib.pyplot.subplot返回的实例和数组(或单个)(数组与否取决于子地块的数量) 常用的是: import matplotli

目前,我正在尝试熟悉matplotlib.pyplot库。在看过很多示例和教程之后,我注意到subplot函数也有一些返回值,这些值通常在以后使用。然而,在matplotlib网站上,我找不到关于返回内容的任何规范,并且没有一个示例是相同的(尽管它通常看起来是一个ax对象)。你们能给我一些关于返回什么以及我如何使用它的指示吗。提前谢谢

中,它表示
matplotlib.pyplot.subplot
返回的实例和数组(或单个)(数组与否取决于子地块的数量)

常用的是:

import matplotlib.pyplot as plt
import numpy as np
f, axes = plt.subplots(1,2)  # 1 row containing 2 subplots.

# Plot random points on one subplots.
axes[0].scatter(np.random.randn(10), np.random.randn(10))

# Plot histogram on the other one.
axes[1].hist(np.random.randn(100))

# Adjust the size and layout through the Figure-object.
f.set_size_inches(10, 5)
f.tight_layout()
通常,matplotlib.pyplot.subplot()返回地物实例和对象或轴对象数组

由于您还没有发布您试图弄脏双手的代码,因此我将通过以下两个测试用例来完成:

案例1:当提到所需的子批次数量(尺寸)时

import matplotlib.pyplot as plt #importing pyplot of matplotlib 
import numpy as np
x = [1, 3, 5, 7]
y = [2, 4, 6, 8]
fig, axes = plt.subplots(2, 1)
axes[0].scatter(x, y)
axes[1].boxplot(x, y)
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt #importing pyplot of matplotlib 
import numpy as np
x = [1, 3, 5, 7]
y = [2, 4, 6, 8]
fig, axes = plt.subplots() 
#size has not been mentioned and hence only one subplot
#is returned by the subplots() method, along with an instance of a figure
axes.scatter(x, y)
#axes.boxplot(x, y)
plt.tight_layout()
plt.show()

正如您在这里看到的,因为我们已经给出了所需的子批次数量,(2,1),在这种情况下,这意味着行数,r=2,列数,c=1。 在这种情况下,子地块返回地物实例以及轴数组,其长度等于子地块的总数=r*c,在这种情况下=2

情况2:未提及子批次(尺寸)数量时

import matplotlib.pyplot as plt #importing pyplot of matplotlib 
import numpy as np
x = [1, 3, 5, 7]
y = [2, 4, 6, 8]
fig, axes = plt.subplots(2, 1)
axes[0].scatter(x, y)
axes[1].boxplot(x, y)
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt #importing pyplot of matplotlib 
import numpy as np
x = [1, 3, 5, 7]
y = [2, 4, 6, 8]
fig, axes = plt.subplots() 
#size has not been mentioned and hence only one subplot
#is returned by the subplots() method, along with an instance of a figure
axes.scatter(x, y)
#axes.boxplot(x, y)
plt.tight_layout()
plt.show()

在这种情况下,没有明确提到尺寸或维度,因此除了figure实例之外,只创建了一个子批次


您还可以使用挤压关键字控制子批次的尺寸。看见它是一个可选参数,默认值为True。

实际上,“matplotlib.pyplot.subplot()”返回两个对象:

  • 图形实例
  • “轴心”
  • “matplotlib.pyplot.subplot()”接受许多参数。具体情况如下:

    matplotlib.pyplot.subplot(nrows=1,ncols=1,*,sharex=False,sharey=False,square=True,subplot\u-kw=None,gridspec\u-kw=None,**fig\u-kw)

    前两个参数是:nrows:我想在子地块网格中创建的行数,ncols:子地块网格中应该包含的列数。但是,如果“nrows”和“ncols”没有被明确地清除,那么默认情况下每个值都将取1

    现在,来看看已经创建的对象: (1) figure实例只是抛出一个包含所有绘图的figure

    (2) “轴”对象将包含关于每个子地块的所有信息

    让我们通过一个例子来理解:

    这里,在(0,0)、(0,1)、(1,0)、(1,1)位置创建了4个子地块

    现在,让我们假设,在(0,0)位置,我想要一个散点图。我将做什么:我将把散点图合并到“轴[0,0]”对象中,该对象将保存散点图的所有信息,并将其反映到地物实例中。 其他三个位置也会发生同样的情况


    希望这会有帮助,让我知道你的想法。

    你是指
    子地块()
    还是
    子地块()
    ?我提到了子地块。我忘记了它们都存在
    plt.subplots()
    返回一个
    图和另一个类型不是常量(标量或数组)的值,除非.Aha,我自己无法从文档中得到这个值。加油!