I am creating a facet plot with the seaborn library with:
JavaScript
x
5
1
titanic = sns.load_dataset('titanic')
2
g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived', height=2, facet_kws=dict(sharex=False, sharey=False))
3
g.set_titles(row_template='{row_name}', col_template='{col_name}')
4
plt.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
5
I would like ALL subplots to have scientific notation.
Using Seaborn version 0.11.2
Advertisement
Answer
- Since the axes are not shared, the format can be set by iterating through each axes.
- This answer shows how to set the tick label format when x and y are shared.
- Tested in
python 3.10
,matplotlib 3.5.1
,seaborn 0.11.2
JavaScript
1
8
1
g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived',
2
height=4, facet_kws=dict(sharex=True, sharey=True))
3
g.set_titles(row_template='{row_name}', col_template='{col_name}')
4
5
# iterate through all the axes
6
for axes in g.axes.flat:
7
axes.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
8