With matplotlib-style figures, I'm aware that using:
import matplotlib.pyplot
plt.ticklabel_format()
allows you to set the axis labels into scientific notation or plain style (to suppress scientific notation). This can also be used in some seaborn plots like scatterplot or lineplot:
import numpy as np
import pandas as pd
import seaborn as sns
a = pd.DataFrame({"Time":np.repeat(np.arange(1e4,5.1e4,1e4),100),
"Speed": np.random.randn(500)})
plt.ticklabel_format(axis="x", style="sci", scilimits=(4,4))
result = sns.scatterplot(x = "Time",y = 'Speed',data = a)
plt.show()
plt.ticklabel_format(axis="x", style="sci", scilimits=(4,4))
result = sns.lineplot(x = "Time",y = 'Speed',data = a)
plt.show()
However, for seaborn plots that generate FacetGrids like catplot
, setting plt.ticklabel_format
is ignored, especially on the categorial axis:
plt.ticklabel_format(axis="x", style="sci", scilimits=(4,4))
result = sns.catplot(x = "Time",y = 'Speed',data = a)
plt.show()
A temporary workaround to this issue involves displaying each number in the categorical variable (Time) as scientific notation as such:
a = pd.DataFrame({"Time": ["{:.0e}".format(i) for i in np.repeat(np.arange(1e4,5.1e4,1e4),100)],
"Speed": np.random.randn(500)})
plt.ticklabel_format(axis="x", style="sci", scilimits=(4,4))
result = sns.catplot(x = "Time",y = 'Speed',data = a)
plt.show()
From my understanding, this is because FacetGrids don't share some attributes with the matplotlib-style plots (like ticklabel_format) or matplotlib doesn't allow scientific notation display on "categorial variables"; likewise, the notation style for this is different from that of the scatter plot. In this case, the exponent is part of each x-value and the base is omitted whereas the scatterplot displays a singular base and exponent for all x-values.
Is there a way to get the FacetGrid from catplot to have the same scientific notation style as the one on the scatter plots?