Python seaborn catplot - 如何将 y 轴刻度更改为百分比

标签 python matplotlib seaborn

在图中,y 轴标签是从(0 到 1)的小数,即(0.1、0.2、0.4 等)。如何将其转换为 % 格式(10%、20%、40% 等)。 10、20、40 也行。

谢谢,约翰

g = sns.catplot(x="who", y="survived", col="class",
...                 data=titanic, saturation=.5,
...                 kind="bar", ci=None, aspect=.6)

最佳答案

您可以在网格的轴上使用 PercentFormatter

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()

enter image description here

关于Python seaborn catplot - 如何将 y 轴刻度更改为百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52512790/

相关文章:

python - 为不包含可映射的图形创建颜色条?

Python:绘制带有彩色类别的直方图

python-3.x - Seaborn箱线图四分位数计算

Python:使用数组作为另一个数组的条件

python - 计算一个 DataFrame 的所有列与另一个 DataFrame 的所有列之间的相关性?

python - 检测鼠标左键和右键单击

python - 如何在子图中绘制多个数据框

python - 如何拆分列表项?

python - 使用python对3D中的2D表面点进行Delaunay三角剖分?

python - 根据数据中的列数动态生成箱线图