Prevent scientific notation in seaborn boxplot

╄→尐↘猪︶ㄣ 提交于 2019-12-31 02:01:27

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/33804658/prevent-scientific-notation-in-seaborn-boxplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!