- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 matplotlib 中使用 GridSpec 创建一个变量(两个不同的)wspace。
到目前为止,我正在使用以下内容:
gs1 = gridspec.GridSpec(6, 3, width_ratios=[1.5,1,1])
gs1.update(wspace=0.4, hspace=0.3)
ax1 = fig.add_subplot(gs1[0:2,0])
ax2 = fig.add_subplot(gs1[2:4,0])
ax3 = fig.add_subplot(gs1[4:6,0])
ax4 = fig.add_subplot(gs1[0:3,1])
ax5 = fig.add_subplot(gs1[3:6,1])
ax6 = fig.add_subplot(gs1[0:3,2])
ax7 = fig.add_subplot(gs1[3:6,2])
知道如何在我惊人的手绘图中获得以绿色突出显示的两个不同空间吗?
非常感谢!
山姆
最佳答案
您可以使用 2 个 GridSpec,一个包含一列和三行,一个包含两行和两列。然后,您可以让第一个仅延伸到图形的一半以下,并从图形宽度的一半开始第二个。 left 和 right 参数之间的差异将是间距。
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs1 = GridSpec(3, 1, right=0.4)
gs2 = GridSpec(2, 2, left=0.5)
ax1 = fig.add_subplot(gs1[0,0])
ax2 = fig.add_subplot(gs1[1,0])
ax3 = fig.add_subplot(gs1[2,0])
ax4 = fig.add_subplot(gs2[0,0])
ax5 = fig.add_subplot(gs2[0,1])
ax6 = fig.add_subplot(gs2[1,0])
ax7 = fig.add_subplot(gs2[1,1])
plt.show()
同样可以通过首先定义一个包含两列的“外部”gridspec 并将一个内部 gridspec 放入其中来实现。
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec
fig = plt.figure()
gs = GridSpec(1, 2, width_ratios=[1.5,2], wspace=0.3)
gs1 = GridSpecFromSubplotSpec(3, 1, subplot_spec=gs[0])
gs2 = GridSpecFromSubplotSpec(2, 2, subplot_spec=gs[1])
ax1 = fig.add_subplot(gs1[0,0])
ax2 = fig.add_subplot(gs1[1,0])
ax3 = fig.add_subplot(gs1[2,0])
ax4 = fig.add_subplot(gs2[0,0])
ax5 = fig.add_subplot(gs2[0,1])
ax6 = fig.add_subplot(gs2[1,0])
ax7 = fig.add_subplot(gs2[1,1])
plt.show()
关于python - python中带有gridspec.GridSpec的变量wspace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51782909/
这个问题已经有答案了: How to plot multiple Seaborn Jointplot in Subplot (4 个回答) 已关闭 5 年前。 我正在处理的一些最小代码。有些参数可能看
我的问题非常简单:我不能在最后一个参数中执行“:”图(strecke, strecke2, "Metern/s 中的 Strecke", "S(t) 图", 0, :)因为它告诉我:“str”和“in
我在使用 matplotlib 的 gridspec 时遇到了一个我似乎无法弄清楚的简单错误。谁能告诉我哪里出错了? import matplotlib.pyplot as plot import m
我正在使用嵌套 GridSpecFromSubplotSpec创建一个嵌套的轴网格。我有两组独立的轴,一个顶部轴和一个底部轴。每组有四个轴,排列在 2x2 网格中。 这是我正在使用的代码和我获得的结果
我目前有 2 个使用 seaborn 的子图: import matplotlib.pyplot as plt import seaborn.apionly as sns f, (ax1, ax2)
我目前有 2 个使用 seaborn 的子图: import matplotlib.pyplot as plt import seaborn.apionly as sns f, (ax1, ax2)
我正在尝试弄清楚如何将另一个立方体形状的图放置在三个子图的右侧 import matplotlib.pyplot as plt import matplotlib.gridspec as gridsp
我正在尝试创建一个类似于以下内容的情节 this question . 为什么我只得到两个面板,即只有 gs2: import numpy as np import matplotlib.pyplot
我有一些代码可以绘制网格,每个单元格中的数据都是不同的并且具有非常特定的位置。我发现执行此操作的最简单方法是使用 gridspec 创建网格并使用它来精确定位我的子图,但是我遇到了一个问题,即整个网格
我有一个 GridSpec 定义的带有子网格的布局,其中一个应该包含一个颜色条 import pylab as plt import numpy as np gs_outer = plt.GridSp
如何在 GridSpec 分割框架中将图像居中?我有下面的图片,我想让上面的图片居中。 相关代码(部分代码,尤其是单元,来自AMUSE框架): lim = [-5,5] | units.kpc bin
我是 python 和 matplotlib 的新手,在调整 2 plot 子图窗口的高度时遇到了问题。我正在尝试使子图垂直对齐,一个直接在另一个之上。底部的子图应该是顶部高度的一半。如果我尝试使用
我想创建一个没有中间空间的地 block 网格。 看起来像这样: 代码 1 import matplotlib.pyplot as plt from matplotlib.gridspec impor
当我使用 matplotlib 和 gridspec 在 python 中创建带有子图的图形时,遇到的问题是无法适当调整子图之间的空间宽度。 虽然 hspace 参数的变体在 0 到 1 的范围内已经
我试图在 6x4 网格中绘制 23 个图形,其中一个图形占其他图形宽度的两倍。我正在使用 gridspec,我当前的代码是: import numpy as np import matplotlib.
我尝试使用 gridspec 在一个图中垂直绘制两个图。上面的应该是下面的两倍高(即比例为 2:1,具有 3 个相等的垂直部分),并且它们必须共享 x 轴比例。我有下面的最小示例,它生成正确的三部分图
有a number of questions关于使用 matplotlib 创建“缩略图”图(即较大图的较小版本,其中缩略图图覆盖在原始图上)。 但是,我找不到使用 GridSpec 绘图来实现此目的
我想创建一个代表数据可视化仪表板的类。仪表板具有特定的预定义布局,我尝试使用 matplotlib.gridspec 来定义它。 仪表板的每个实例的布局都是固定的,但应填充不同的绘图。如何最好地初始化
使用 GridSpec ,我有一个规则的地 block 格。假设 3 x 3。所有绘图轴都关闭,因为我对绘图的形状感兴趣,而不是单个轴值。 我想做的是标记较大框的 x 轴和 y 轴。例如,在上面的 3
我的子图在图中的位置有点奇怪。顶部、底部和左侧有大量空间,我不需要,但右边距离右轴标签有点太近了。请参阅示例。 我生成的代码如下。请注意,我使用了 tight_layout 和 subplots_ad
我是一名优秀的程序员,十分优秀!