34

Simple example below for this issue which I just can't solve.

N.B. Some other Seaborn plotting methods seems to have arguments to repress the exponential form but seemingly not factorplots. I tried some Matplotlib solutions including those suggested in this similar question but none work. Also this is not a dupe of this question. I use factorplots very frequently and ideally want to find a proper solution as opposed to a workaround.

data = {'reports': [4, 24, 31, 2, 3],'coverage': [35050800, 54899767, 57890789, 62890798, 70897871]}
df = pd.DataFrame(data)
df

Produces this dataframe:

    coverage    reports
0   35050800    4
1   54899767    24
2   57890789    31
3   62890798    2
4   70897871    3

And then this Seaborn code:

sns.factorplot(y="coverage", x="reports", kind='bar', data=df, label="Total") 

Produces this plot:

enter image description here

Is there a way to get the y axis to display an appropriate numeric scale based on the coverage values?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
RDJ
  • 4,052
  • 9
  • 36
  • 54
  • Possible duplicate of [How to prevent numbers being changed to exponential form in Python matplotlib figure](http://stackoverflow.com/questions/14711655/how-to-prevent-numbers-being-changed-to-exponential-form-in-python-matplotlib-fi) – GWW Apr 21 '16 at 22:12
  • Thanks for highlighting this possibility GWW - I had seen that question and tried the solutions but to no avail. – RDJ Apr 21 '16 at 22:28
  • 2
    Have You tried `plt.ticklabel_format(style='plain', axis='y')`? – Tony Babarino Apr 21 '16 at 22:39
  • @TonyBabarino - Never thought of that. Works perfectly. If you post it as an answer I'll accept it. – RDJ Apr 21 '16 at 22:44
  • posted, glad I could help, cheers! – Tony Babarino Apr 21 '16 at 22:48
  • @RDJ: I retracted my vote. I used the duplicate answer before with success so I am surprised it didn't work for you. – GWW Apr 21 '16 at 22:52
  • @gww I would be interested to know exactly how you did it syntactically as it definitely didn't work the way I tried it. – RDJ Apr 21 '16 at 22:56

3 Answers3

44

It looks like the following line solves the issue:

plt.ticklabel_format(style='plain', axis='y')

Here is the documentation link.

Tony Babarino
  • 3,355
  • 4
  • 32
  • 44
6

Following line solved the issue for me (addition to Tony's answer)

sns.plt.ticklabel_format(style='plain', axis='y',useOffset=False)

sarc360
  • 349
  • 3
  • 5
0

You can use globally the "rc-Paramter" when you don't want to import and deal with matplotlib directly.

sns.set_theme(rc={'axes.formatter.limits': (-8, 9)})

See:

buhtz
  • 10,774
  • 18
  • 76
  • 149