fig, axes = plt.subplots(4,3, figsize=(17,17))
axes = axes.flatten()
labels = ['d','f']
l1 = sns.histplot(ax=axes[0],hue=dff_2k['source'],x='a', data=dff_2k)
l2 = sns.histplot(ax=axes[1],hue=dff_2k['source'],x='b', data=dff_2k)
l3 = sns.histplot(ax=axes[2],hue=dff_2k['source'],x='c', data=dff_2k)
l4 = sns.histplot(ax=axes[3],hue=dff_2k['source'],x='d', data=dff_2k)
l5 = sns.histplot(ax=axes[4],hue=dff_2k['source'],x='e', data=dff_2k)
l6 = sns.histplot(ax=axes[5],hue=dff_2k['source'],x='f', data=dff_2k)
l7 = sns.histplot(ax=axes[6],hue=dff_2k['source'],x='g', data=dff_2k)
l8 = sns.histplot(ax=axes[7],hue=dff_2k['source'],x='h', data=dff_2k)
l9 = sns.histplot(ax=axes[8],hue=dff_2k['source'],x='i', data=dff_2k)
l10 = sns.histplot(ax=axes[9],hue=dff_2k['source'],x='j', data=dff_2k)
l11 = sns.histplot(ax=axes[10],hue=dff_2k['source'],x='k', data=dff_2k)
l12 = sns.histplot(ax=axes[11],hue=dff_2k['source'],x='l', data=dff_2k)
fig.legend([l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12],labels=labels,loc='upper right')
axes[0].get_legend().remove()
axes[1].get_legend().remove()
axes[2].get_legend().remove()
axes[3].get_legend().remove()
axes[4].get_legend().remove()
axes[5].get_legend().remove()
axes[6].get_legend().remove()
axes[7].get_legend().remove()
axes[8].get_legend().remove()
axes[9].get_legend().remove()
axes[10].get_legend().remove()
axes[11].get_legend().remove()
plt.show()
How can I minimize this code? I just want to add only features and then axis to create the different subplots.
CodePudding user response: