0

I want to set the gridlines behind the boxplots. It´s possible with set_style("whitegrid"), but then i only get the major ticks, and i nedd the minors also.

This is my code. I set the log scale and and the grid for minor and major ticks on the y-axis.

import os
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
#import data
path = r"C:\Users\damjan\Desktop\Boxplots\Lastenstraße\Lastenstraße1028.xlsx"
#dataframe
df = pd.DataFrame(pd.read_excel(path))
my_colors = {'Gut': 'green', 'Mittel': 'orange', 'Schlecht': 'red'}

ax = plt.subplot()
plt.figure(figsize= [12,8], dpi= 300)
plt.grid(True, 'both','y')
ax.set_axisbelow(True)
sns.boxplot(data= df, x = "Himmelsrichtung", y ="kT [m²10^-16]", hue="Nachbehandlung", palette= my_colors)
plt.yscale('log')

this is the output: plot

How can i set the gridlines to the background? Thank you, in advance.

Damiano
  • 3
  • 3
  • You need to call `ax = plt.subplot()` after `plt.figure`, not before. – JohanC Feb 16 '23 at 10:25
  • Ok i answered my own question. By calling sns.set_style("whitegrid") and the setting the rcParams plt.rcParams.update({"xtick.bottom" : True, "ytick.left" : True}) plt.rcParams['axes.grid.which'] = 'both' – Damiano Feb 16 '23 at 10:25

0 Answers0