- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是编码方面的新手,因此也是 Python 方面的新手,所以这听起来可能很愚蠢,但是 Python 中 matplotlib 的 .subplot() 和 .subplots() 方法之间的主要区别是什么?
在阅读来自 https://matplotlib.org/ 的文档后,我没有在其他任何地方找到此解释。我推断,使用这两种方法,您都可以根据需要创建任意数量的图形和绘图……所以对我来说,它们似乎是完全相同的东西,它们只是处理绘图、轴等的方式不同……还是我错了?
顺便说一句,我在 jupyter notebook 中使用 python3,如果它有任何不同的话。
最佳答案
matplotlib.pyplot.subplots()
来自 matplotlib.pyplot.subplots()
的文档页面:
This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.
这意味着您只需使用一行代码,就可以使用这个函数创建一个包含多个子图的图形。例如,下面的代码将返回图形对象 fig
和轴对象的 2x3 数组 axes
,它允许您轻松访问每个子图:
fig, axes = plt.subplots(nrows=2, ncols=3)
matplotlib.pyplot.subplot()
相比之下,matplotlib.pyplot.subplot()
在指定的网格位置仅创建一个子图轴。这意味着它将需要几行代码来实现与 matplot.pyplot.subplots()
在上面的一行代码中所做的相同的结果:
# first you have to make the figure
fig = plt.figure(1)
# now you have to create each subplot individually
ax1 = plt.subplot(231)
ax2 = plt.subplot(232)
ax3 = plt.subplot(233)
ax4 = plt.subplot(234)
ax5 = plt.subplot(235)
ax6 = plt.subplot(236)
或者你也可以使用fig
的内置方法:
ax1 = fig.add_subplot(231)
ax2 = fig.add_subplot(232)
ax3 = fig.add_subplot(233)
ax4 = fig.add_subplot(234)
ax5 = fig.add_subplot(235)
ax6 = fig.add_subplot(236)
上面的代码可以用一个循环来压缩,但是使用起来还是比较繁琐。因此,我建议您使用 matplotlib.pyplot.subplots()
,因为它更简洁且易于使用。
关于Python - matplotlib - subplot() 和 subplots() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52214776/
我有点不清楚如何subplot作品。具体来说subplot(121)有什么区别和 subplot(1,2,1)在 MATLAB 中?我试图搜索 subplot文档,但我似乎找不到我要找的东西。 最佳答
我是编码方面的新手,因此也是 Python 方面的新手,所以这听起来可能很愚蠢,但是 Python 中 matplotlib 的 .subplot() 和 .subplots() 方法之间的主要区别是
def plot_it(U1, U2, x, i): fig_1, = plt.plot(x, U1) fig_2, = plt.plot(x, U2) i = str(int
有时候想要把几张图放在一起plot,比较好对比,subplot和subplots都可以实现,具体对比可以查看参考博文。这里用matplotlib库的subplot来举个栗子。 数据长什么样 有两
在matplotlib中,用subplots画子图时,有时候需要调整子图间矩,包括子图与边框的间矩,子图间上下间矩,子图间左右间矩,可以使用fig.tight_layout()函数:
如下所示: matplotlib subplots 设置总图的标题 : fig.suptitle(dname,fontsize=16,x=0.53,y=1.05,) 以上这篇matplotli
我不知道如何使用 R 和 Plotly 使表格子图正常工作。 下面演示了我的意思。我有两张图,一张散点图和一张 table 。使用 subplot 函数,表格图的行为不符合预期。 我要么在散点图上失去
我正在尝试绘制一些子图,但似乎无法共享轴。我看过其他代码,他们似乎完全按照我的尝试做,但我的似乎没有做任何事情。 我只是想在左侧的四个子图中共享各自的轴,同时将最右侧的子图分开。 import num
我想在子图的底部添加一个图例(2 x 2): 正如您所看到的,由于我手动调整了第二行中的图表,因此被挤压了一点。 是否有像 sublegend(...) 这样的函数,或者它是否涉及大量编码? 来源 这
在使用 Matplotlib 绘图时,我们大多数情况下,需要将一张画布划分为若干个子区域,之后,我们就可以在这些区域上绘制不用的图形。在本节,我们将学习如何在同一画布上绘制多个子图。 matplotl
matplotlib.pyplot模块提供了一个 subplots() 函数,它的使用方法和 subplot() 函数类似。其不同之处在于,subplots() 既创建了一个包含子图区域的画布,又创建
使用 plotly 的 subplots() 时,如何删除图例中的重复项? 这是我的 MWE: library(plotly) library(ggplot2) library(tidyr) mpg
如何调整某些子图之间的空白?在下面的示例中,假设我想消除第 1 个和第 2 个子图之间以及第 3 个和第 4 个之间的所有空白,并增加第 2 个和第 3 个之间的空间? import matplotl
如果我绘制如下所示的单个图表,其大小将为 (x * y)。 import matplotlib.pyplot as plt plt.plot([1, 2], [1, 2]) 但是,如果我在同一行中绘制
我需要在网格中显示20张图像,我的代码如下 def plot_matric_demo(img, nrows, ncols): fig, ax = plt.subplots(nrows=nrow
这个问题在这里已经有了答案: How to plot in multiple subplots (12 个答案) 关闭去年。 我在一些帮助下构建了一组饼图 Insert image into pie
我正在寻找一种方法来创建一个包含多个子图的绘图 fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True) 会在 matplotlib 中执行,然后可以通
当我使用 PyPlot 的 figure() 函数创建单个绘图时,我可以使用字符串作为参数来设置出现窗口的名称: import matplotlib.pyplot as plt figure = pl
我想要一个由四个子图组成的图形。其中两个是通常的线图,其中两个是 imshow-images。 我可以将 imshow-images 格式化为正确的绘图本身,因为它们中的每一个都需要自己的颜色条、修改
我在使用 plt.subplots 时尝试更改图形大小时遇到了一些麻烦。使用下面的代码,我只得到标准尺寸的图表,其中包含我所有的子图(大约有 100 个),并且显然只是一个额外的空 figures
我是一名优秀的程序员,十分优秀!