The x axis on my catplot currently consists of categorical decimal values as such:
[0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8. 0.9, 1.0]
I'm using the following to try to format to a percentage, but it's returning value values 10x greater than expected:
for axis in ax.axes.flat:
axis.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, p: f'{x:.0%}'))
axis.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, p: f'{y:.2%}'))
currently yields:
[0, 100%, 200%, 300%, 400%, 500%, 600%, 700%, 800%, 900%, 1000%]
The y-axis is formatted correctly, not sure why the x-axis is returning values higher than expected.
Internally, seaborn plots categorical variables at x=[0, 1, 2, ..., 10]
, so that's why the percentage formatter is returning x=[0, 100, 200, ..., 1000]
.
In this case, you can apply the %
f-string directly with set_xticklabels
:
xticks = [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
for axis in ax.axes.flat:
axis.set_xticklabels([f'{x:.0%}' for x in xticks])
axis.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, p: f'{y:.2%}'))