I need to plot 7 charts in a subplot, rather than 7 individual plots and unsure how to add the sub-plotting to this without having to manually subplot each graph, rather than in a loop
This is a snippet of my code:
year = ['2018','2019','2020','2021','2022','2023','2024']
for Year in year:
palette = {
'Q1': 'tab:blue',
'Q2': 'tab:green',
'Q3': 'tab:orange',
'Q4': 'tab:red',
}
sns.scatterplot(data=dfSumDate.loc[Year], x='Temperature',
y='MeanEnergy', hue='Season', palette=palette)
plt.ylim(0,120)
plt.xlim(-5,30)
plt.title(Year)
plt.show()
Would ideally have these be plotted in a 4x2 grid, thank you

Using Seaborn's FacetGrid
The easiest way to automatically create the subplots, is via Seaborn's
FacetGrid.sns.relplot(...)creates such a grid for scatter plots. For this to work, the'Year'needs to be an explicit column of the dataframe.Here is some example code:
With the
ax=keywordAlternatively, Seaborn's "axes level" functions accept an
ax=keyword where you can set the subplot ("ax") on which the plot needs to be drawn: