Skip to content
Advertisement

How to set axis label format to scientific format in seaborn relplot with facets when axes are not shared

I am creating a facet plot with the seaborn library with:

titanic = sns.load_dataset('titanic')
g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived', height=2, facet_kws=dict(sharex=False, sharey=False))
g.set_titles(row_template='{row_name}', col_template='{col_name}')
plt.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))

enter image description here

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
g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived',
                height=4, facet_kws=dict(sharex=True, sharey=True))
g.set_titles(row_template='{row_name}', col_template='{col_name}')

# iterate through all the axes
for axes in g.axes.flat:
    axes.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))

enter image description here

Advertisement