I'm working with a lot of csv files each representing a different submarine channel (underwater river). I have been writing functions to create various plots with seaborn (violin plots, distplots etc.) for each channel and have encountered a problem when trying to loop over and plot a number of different columns in a dataframe as subplots. The problem is that the three subplots generated appear blank and the plots produced, while correct, appear individually, not as the three subplots I'd like. I used a very similar piece of code to generate 3 violin plots and it worked fine.
What am I missing? I am pretty new to python and can't figure it out.
def distPlots(df, fname):
"""
df : dataframe
filename : string for file export
"""
copy = df.drop('Channel', axis=1)
cols = copy.columns
col_labels = ["Width (m)", "Height (m)", "Aspect ratio"]
fig, ax = plt.subplots(1, 3, figsize=(17, 5))
for var, label, subplot in zip(cols, col_labels, ax.flatten()):
sns.displot(x=var, hue="Channel", data=df, kde=True, bins=20, ax=subplot)
subplot.set_xlabel(label)
plt.tight_layout()
plt.show()
plt.draw()
fig.savefig(fname)
distPlots(data_chc1, 'ChC1_distPlots.pdf')