I am trying to plot five columns per iteration, but current code is ploting everithing five times. How to explain to it to plot five columns per iteration without repeting them?
n=4
for tag_1,tag_2,tag_3,tag_4,tag_5 in zip(df.columns[n:], df.columns[n 1:], df.columns[n 2:], df.columns[n 3:], df.columns[n 4:]):
fig,ax=plt.subplots(ncols=5, tight_layout=True, sharey=True, figsize=(20,3))
sns.scatterplot(df, x=tag_1, y='variable', ax=ax[0])
sns.scatterplot(df, x=tag_2, y='variable', ax=ax[1])
sns.scatterplot(df, x=tag_3, y='variable', ax=ax[2])
sns.scatterplot(df, x=tag_4, y='variable', ax=ax[3])
sns.scatterplot(df, x=tag_5, y='variable', ax=ax[4])
plt.show()
CodePudding user response:
You are using list slicing in the wrong way. When you use df.columns[n:]
, you are getting all the column names from the one with index n
to the last one. The same is valid for n 1
, n 2
, n 3
and n 4
. This causes the repetition that you are referring to. In addition to that, the fact that the plot is shown five times is due to the behavior of the