Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading