How can I force scientific notation on the axes of a seaborn.FacetGrid
or seaborn.catplot
again?
import seaborn as sns
sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
Thanks!
The key is here:
plt.ticklabel_format(axis="x", style="sci", scilimits=(0,0))
plt.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
Complete code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
a = pd.DataFrame({"x": np.random.randn(500),
"y": np.random.randn(500)*200})
import seaborn as sns
sns.set_theme(style="ticks")
g = sns.catplot( data=a)
plt.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
plt.show()
Seaborn will use scientific notation automatically if your number is large (note the value of y
):
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
a = pd.DataFrame({"x": np.random.randn(500),
"y": np.random.randn(500)*1000000000})
import seaborn as sns
sns.set_theme(style="ticks")
g = sns.catplot( data=a)
# plt.ticklabel_format(style='plain', axis='y')
plt.show()
Just use
plt.ticklabel_format(style='plain', axis='y')
Complete code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
a = pd.DataFrame({"x": np.random.randn(500),
"y": np.random.randn(500)*200})
import seaborn as sns
sns.set_theme(style="ticks")
g = sns.catplot( data=a)
plt.ticklabel_format(style='plain', axis='y')
plt.show()
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.