Python 3.x subplot()为参数';获取了多个值;nrows&x27;在子地块中循环时

Python 3.x subplot()为参数';获取了多个值;nrows&x27;在子地块中循环时,python-3.x,matplotlib,plot,figure,Python 3.x,Matplotlib,Plot,Figure,我正在尝试创建一段代码,让我能够循环使用从一台吐出可变数据量的机器创建的尽可能多的子批次。有时我会有几个情节,有时我会有30多个。代码似乎运行得很好,只是当我运行它时,我的绘图总是看起来像被压扁了一样。当我尝试将ncols参数或nrows参数传递给代码时,它会显示: subplot()在子批中循环时为参数“nrows”获取了多个值 这是我的密码: conditions = 15 colors = ['purple', 'blue', 'plum', 'green'] condition_nam

我正在尝试创建一段代码,让我能够循环使用从一台吐出可变数据量的机器创建的尽可能多的子批次。有时我会有几个情节,有时我会有30多个。代码似乎运行得很好,只是当我运行它时,我的绘图总是看起来像被压扁了一样。当我尝试将ncols参数或nrows参数传递给代码时,它会显示:

subplot()在子批中循环时为参数“nrows”获取了多个值

这是我的密码:

conditions = 15 
colors = ['purple', 'blue', 'plum', 'green']
condition_names = ['One', 'Two', 'Three', 'Four']

rows=3
cols=5
fig, axes = plt.subplots(conditions, sharex=True, sharey=True, figsize=(18,25), nrows=rows, ncols=cols)



q = 0
c = 0
d = 0
total = len(En_cols)

try:
    for i in En_cols:
        q = q
        lines = En_cols
        axes[d].errorbar(data=En_means, x=Num_x_axis, y=En_means[lines[q]], yerr=En_devs[lines[q]], c=colors[c], ecolor=colors[c], capsize=5, marker='s',linestyle ='--', label=condition_names[c])
        q = q + conditions
        c = c + 1
        axes[d].errorbar(data=En_means, x=Num_x_axis, y=En_means[lines[q]], yerr=En_devs[lines[q]], c=colors[c], ecolor=colors[c], capsize=5, marker='s',linestyle ='--', label=condition_names[c])
        q = q + conditions
        c = c + 1
        axes[d].errorbar(data=En_means, x=Num_x_axis, y=En_means[lines[q]], yerr=En_devs[lines[q]], c=colors[c], ecolor=colors[c], capsize=5, marker='s',linestyle ='--', label=condition_names[c])
        q = q + conditions
        c = c + 1
        axes[d].errorbar(data=En_means, x=Num_x_axis, y=En_means[lines[q]], yerr=En_devs[lines[q]], c=colors[c], ecolor=colors[c], capsize=5, marker='s',linestyle ='--', label=condition_names[c])
        q = q + conditions
        c = c + 1

        c = 0 
        d = d + 1
        q = q + 1
        q = q - conditions*4
        continue
except IndexError:
        pass

有没有办法让我的身材看起来不那么糟糕?
谢谢

您不能同时使用
条件
作为位置参数和
nrows=
作为关键字参数,这就是为什么会出现此错误

我建议您决定需要多少列(可以与条件的数量成比例),然后计算行的数量

但是请注意,
subplot()
将返回轴的2D数组。但您可以使用
axes.flatte()[i]

e、 g:


什么是
条件
?还有什么是
En_cols
import math

conditions = 16 
cols = 5
rows = math.ceil(conditions/cols)
fig, axes = plt.subplots(nrows=rows, ncols=cols, sharex=True, sharey=True)