代码之家  ›  专栏  ›  技术社区  ›  J-H

Python Seaborn Facetgrid更改xlabels

  •  13
  • J-H  · 技术社区  · 8 年前

    我只是不知道如何在Seaborn Facetgrid中更改xlabel。它提供了一种使用set_xlabels()更改x标签的方法,但不幸的是,不能针对每个子地块单独更改。

    我有两个子地块,它们共享y轴,但具有不同的x轴,我想用不同的文本标记它们。

    谁能给我一个提示吗。提前谢谢你。

    2 回复  |  直到 8 年前
        1
  •  34
  •   tmdavison    8 年前

    您可以访问 FacetGrid 使用 axes 属性,然后使用 set_xlabel() 在它们的每一个上。例如:

    import seaborn as sns
    import matplotlib.pyplot as plt
    
    sns.set(style="ticks", color_codes=True)
    
    tips = sns.load_dataset("tips")
    
    g = sns.FacetGrid(tips, col="time",  hue="smoker")
    g = g.map(plt.scatter, "total_bill", "tip", edgecolor="w")
    
    g.axes[0,0].set_xlabel('axes label 1')
    g.axes[0,1].set_xlabel('axes label 2')
    
    plt.show()
    

    enter image description here

    注意,在该示例中, g.axes 形状为 (1,2) (一行,两列)。

        2
  •  0
  •   user690069    3 年前

    对于所有轴,只要使用此项即可设置它们

    g.set_axis_labels("Total bill ($)")