How to prevent seaborn boxplot from automatically show axis with exponential numbers?

How can i prevent a boxplot in seaborn from showing the y-axis values as exponential numbers?

This is the code:

fig, ax = plt.subplots(1, 1)
boxplot = sns.boxplot(x=df.param1, y=df.param2, data=pd.melt(df),  ax=ax).set(
            xlabel='xLabel', 
            ylabel='yLabel')

Any sort of advice is kindly apprechiated!

I have tried

boxplot.get_xaxis().get_major_formatter().set_scientific(False)

and

boxplot.yaxis.get_major_formatter().set_scientific(False)
boxplot.yaxis.get_major_formatter().set_useOffset(False)

and

labels = ['%.5f' % float(t.get_text()) for t in ax.get_xticklabels()]
ax.set_yticklabels(labels)

after the boxplot configuration line but nothing seems to work.

>Solution :

You could try setting the sci parameter of y-axis tick formatter to False.

import matplotlib.ticker as ticker

fig, ax = plt.subplots(1, 1)
boxplot = sns.boxplot(x=df.param1, y=df.param2, data=pd.melt(df),  ax=ax).set(
            xlabel='xLabel', 
            ylabel='yLabel')

ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%.5f'))
ax.yaxis.get_major_formatter().set_scientific(False)

Leave a Reply