代码之家  ›  专栏  ›  技术社区  ›  Soerendip

如何将轴标签格式设置为科学格式的seaborn重绘与刻面?

  •  0
  • Soerendip  · 技术社区  · 4 年前

    我正在与seaborn图书馆一起创建一个平面图,其中包括:

    titanic = sns.load_dataset('titanic')
    g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived', height=2, facet_kws=dict(sharex=False, sharey=False))
    g.set_titles(row_template='{row_name}', col_template='{col_name}')
    plt.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
    

    enter image description here

    我希望所有的子情节都有科学的注释。

    使用Seaborn版本0.11.2

    0 回复  |  直到 4 年前
        1
  •  1
  •   Trenton McKinney ivirshup    4 年前
    • 由于轴是不共享的,因此可以通过迭代每个轴来设置格式。
    • answer 显示了在共享x和y时如何设置刻度标签格式。
    • 测试时间 python 3.10 , matplotlib 3.5.1 , seaborn 0.11.2
    g = sns.relplot(data=titanic, x='fare', y='age', col='sex', row='survived',
                    height=4, facet_kws=dict(sharex=True, sharey=True))
    g.set_titles(row_template='{row_name}', col_template='{col_name}')
    
    # iterate through all the axes
    for axes in g.axes.flat:
        axes.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
    

    enter image description here