好的,所以我一直试图从昨天开始解决这个问题,并且找不到解决方案。使用迭代来自不同熊猫数据帧的列的循环创建Matplotlib子图
我为12个不同实验的数据创建了12个熊猫数据框(名为exp_1 - exp_12),列名在所有数据框中都是相同的。我想创建一个有12个小区(12x4)的地块,每个实验每行4个地块。
到目前为止,这么好。绘制的作品就好了,我目前使用此代码(我把它缩短到这里4个地块):
fig, axs = plt.subplots(nrows = 12, ncols=4, figsize = (15,27))
sns.regplot('MecA_SP', 'MecA_MP', data=exp_3, color ='blue', ax=axs[0,0])
sns.regplot('blaOXA_SP', 'blaOXA_MP', color ='lime', data=exp_3,
ax=axs[0,1])
sns.regplot('Aph3_SP', 'Aph3_MP', data=exp_3, color = 'deeppink',
ax=axs[0,2])
sns.boxplot(data=exp_3, orient ='h', color ='darkviolet', ax=axs[0,3])
fig.tight_layout()
plt.show()
但是我想通过一个循环来创建这些插曲让我不必手动为每个数据帧输入每个样本名称。现在,这是我有:
fig, axs = plt.subplots(nrows = 12, ncols=4, figsize = (14,5))
exps = {0: 'exp_1',1: 'exp_2',2: 'exp_3',3: 'exp_4',4: 'exp_5',5: 'exp_6',
6:'exp_7',7: 'exp_8', 8:'exp_9',9: 'exp_10',10: 'exp_11',11: 'exp_12'}
for x in exps :
sns.regplot('MecA_SP', 'MecA_MP', data=x, color ='blue', ax=axs[exps[x],
0])
sns.regplot('blaOXA_SP', 'blaOXA_MP', color ='lime', data=x,
ax=axs[exps[x], 1])
sns.regplot('Aph3_SP', 'Aph3_MP', data=x, color = 'deeppink',
ax=axs[exps[x], 2])
sns.boxplot(data=x, orient ='h', color ='darkviolet', ax=axs[exps[x],3])
fig.tight_layout()
plt.show()
这就是我什么我的情节看起来像如果我不使用循环,而只是用手工写了整个事情: enter image description here
有谁有一个想法,我可以解决这个问题?我会很乐意提供任何建议,所以在此先感谢
您的数据在哪里? –
我在上一步中将所有数据保存到数据框(exp_1-exp_12)中。你想让我把它发布在这里吗?这是很多数据,这就是为什么我把它排除在外 –