ValueError:行数必须是正整数,而不是GridSpec(2,1,高度/单位比率=[1,3])[1:2,0:1]python matplotlib

ValueError:行数必须是正整数,而不是GridSpec(2,1,高度/单位比率=[1,3])[1:2,0:1]python matplotlib,python,matplotlib,Python,Matplotlib,尝试使用gridspec生成一个2行1列的子图,并不断得到错误 ValueError: Number of rows must be a positive integer, not GridSpec(2, 1, height_ratios=[1, 3])[1:2, 0:1] 使用代码时 fig, ax = plt.subplots(figsize = (8,6)) gs = gridspec.GridSpec(2,1,height_ratios = [1,3]) 我一辈子都不知道为什么。我希

尝试使用gridspec生成一个2行1列的子图,并不断得到错误

ValueError: Number of rows must be a positive integer, not GridSpec(2, 1, height_ratios=[1, 3])[1:2, 0:1]
使用代码时

fig, ax = plt.subplots(figsize = (8,6))
gs = gridspec.GridSpec(2,1,height_ratios = [1,3])

我一辈子都不知道为什么。我希望顶部的子地块宽度相同,但高度约为下方地块的1/3。

'GridSpec'应采用以下格式

import matplotlib.pyplot as plt
from matplotlib import gridspec

fig, ax = plt.subplots(figsize = (8,6))
fig.clf()

gs = gridspec.GridSpec(2,1, height_ratios=[3,1], hspace=0.2)
ax1 = fig.add_subplot(gs[0,0])
ax2 = fig.add_subplot(gs[1,0])

'GridSpec'应采用以下格式

import matplotlib.pyplot as plt
from matplotlib import gridspec

fig, ax = plt.subplots(figsize = (8,6))
fig.clf()

gs = gridspec.GridSpec(2,1, height_ratios=[3,1], hspace=0.2)
ax1 = fig.add_subplot(gs[0,0])
ax2 = fig.add_subplot(gs[1,0])

我看到了我犯的错误。我有ax1=图。。。。。但是使用了子批次“s”而不是子批次。我看到了我犯的错误。我有ax1=图。。。。。但是使用子地块“s”而不是子地块。