Warm tip: This article is reproduced from serverfault.com, please click

Remove scientific notation from catplot in seaborn

发布于 2020-11-26 01:51:21

Executing the following:

g = sns.catplot(x="price", y="neigh", kind="bar", data=top_bot).set(title = "Mean of the top and bottom prices (euros) by neighbour")

enter image description here

The x ticks are being converted to scientific notation. I would like to specify the ticks to use, and also remove the scientific notation from them. I tried several approaches already posted in ´SO´, but the problem is that neither of them worked specifically with catplot.

Edit: This solution doesn't solve my problem at all. For plt.ticklabel_format(style='plain', axis='y') creates an empty plot, followed by the same plot in scientific notation. and for sns.plt.ticklabel_format(style='plain', axis='y',useOffset=False) it outputs AttributeError: module 'seaborn' has no attribute 'plt'

Questioner
Norhther
Viewed
0
mosc9575 2020-11-29 17:55:30

This is how to use seaborn and matplotlib functionality together. You have to create a matplotlib figure first and make all the changes you need. Than call the seaborn function and adding the information about the axes you want to use.

This is a working minimal example.

import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
# data
top_bot = pd.DataFrame({'price':[i*100000000 for i in range(5)], 'neigh': range(10,15)})
# creating figure
f, ax = plt.subplots()
ax.ticklabel_format(style='plain', axis='both')
sns.barplot(x='price', y='neigh', data=top_bot, ax=ax)

This example in different from your picture, because you did not share the data you have plotted and the code you tried.

I hope this answers your question.