1

I am trying to plot temperature data recorded over the year using a seaborn violinplot.

I manage to do the following plot:

Seaborn violinplor from march to december

I would like to start the plot in January, even if the data collection starts in March for 2021, in order to display yearly plots on top of each other and be able to visually compare same months of different years.

I tried the following use of set_xlim, but it didn't work

fig, ax = plt.subplots(figsize=(24,10))
fontsize=18
ax.set_xlim(1,12)
plt.rc('xtick', labelsize=fontsize) 
plt.rc('ytick', labelsize=fontsize) 

plt.rcParams['font.size']=24

seaborn.violinplot(x = weather21_2h.index.month, y = weather21_2h['T out_x'], ax=ax, palette="GnBu",inner = "box")
plt.title('Statistique des températures par mois 2021')
plt.xlabel('Mois', fontsize=24)
plt.ylabel('Températures (°C)')

plt.grid(True)

plt.show()

Is there a way ?

Zephyr
  • 11,891
  • 53
  • 45
  • 80

1 Answers1

2

You can simply pass order parameter to saeborn.violinplot:

fig, ax = plt.subplots(figsize=(24,10))
fontsize=18

plt.rc('xtick', labelsize=fontsize)
plt.rc('ytick', labelsize=fontsize)

plt.rcParams['font.size']=24

sns.violinplot(x = weather21_2h.index.month,
               y = weather21_2h['T out_x'],
               ax=ax,
               palette="GnBu",
               inner = "box",
               order = range(1, 13))

ax.set_title('Statistique des températures par mois 2021')
ax.set_xlabel('Mois', fontsize=24)
ax.set_ylabel('Températures (°C)')

ax.grid(True)

plt.show()

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80