问题
In the figure the y-axis labels are in decimals from (0 to 1) i.e (0.1, 0.2, 0.4 etc). How can I convert this into a % format (10%, 20%, 40% etc). Just 10, 20, 40 also will do.
Thanks, John
g = sns.catplot(x="who", y="survived", col="class",
... data=titanic, saturation=.5,
... kind="bar", ci=None, aspect=.6)
回答1:
You may use a PercentFormatter
on the axes of the grid.
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter
titanic = sns.load_dataset("titanic")
g = sns.catplot(x="who", y="survived", col="class",
data=titanic, saturation=.5,
kind="bar", ci=None, aspect=.6)
for ax in g.axes.flat:
ax.yaxis.set_major_formatter(PercentFormatter(1))
plt.show()
来源:https://stackoverflow.com/questions/52512790/python-seaborn-catplot-how-do-i-change-the-y-axis-scale-to-percentage