[英]Python seaborn catplot - How do I change the y-axis scale to percentage
在圖中,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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.