简体   繁体   中英

Prevent scientific notation in seaborn boxplot

I'm using pandas version 0.17.0 , matplotlib version 1.4.3 and seaborn version 0.6.0 to create a boxplot. I want all values on the x-axis in float notation. Currently the two smallest values (0,00001 and 0,00005) are formatted in scientific notation.

Here's the code I use to plot the image:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

data = pd.read_csv("resultsFinal2.csv")

boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"))

plt.show()

As suggested in How to prevent numbers being changed to exponential form in Python matplotlib figure , i tried:

boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"))
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_scientific(False)

resulting in:

    plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
AttributeError: 'FixedFormatter' object has no attribute 'set_useOffset'

Seaborn Boxplot documentation says, I can pass an Axes object to draw the plot onto. So I tried to create an axis with scientific notation disabled and passed it to sns.boxplot:

ax1 = plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"), ax=ax1)

That didn't work either. Can someone tell me how to do it?

This might be an ugly solution, but it works, so who cares

fig, ax = plt.subplots(1, 1)
boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"), ax=ax)
labels = ['%.5f' % float(t.get_text()) for t in ax.get_xticklabels()]
ax.set_xticklabels(labels)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM