【问题标题】:Python Seaborn Facetgrid change xlabelsPython Seaborn Facetgrid 更改 xlabels
【发布时间】:2016-08-03 02:18:52
【问题描述】:

我只是不知道如何更改 Seaborn Facetgrid 中的 xlabels。它提供了一种使用 set_xlabels() 更改 x 标签的方法,但不幸的是不是每个子图都单独更改。

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

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

【问题讨论】:

    标签: python matplotlib plot dataframe seaborn


    【解决方案1】:

    为所有轴设置一次使用这个

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

    【讨论】:

      【解决方案2】:

      您可以使用axes 属性访问FacetGrid 的各个轴,然后在每个轴上使用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()
      

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

      【讨论】:

      • 非常感谢您的帮助。完美运行。我想我必须仔细看看 matplotlib。
      • 我可以在两个图表的中心设置一个标签吗?
      • 我的意思是在一次拍摄中,没有把所有 g.axes[n,n] 设为空白值
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 2016-01-25
      相关资源
      最近更新 更多