简体   繁体   中英

Remove scientific notation from catplot in seaborn

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")

在此处输入图像描述

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'

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.

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