【问题标题】:How can I add title on seaborn lmplot?如何在 seaborn lmplot 上添加标题?
【发布时间】:2018-02-28 16:21:47
【问题描述】:

我正在尝试在 Searbon lmplot 上添加标题。

ax = plt.axes()
sns.lmplot(x, y, data=df, hue="hue", ax=ax)
ax.set_title("Graph (a)")
plt.show()

但我注意到lmplot 没有ax 参数。 如何在我的 lmplot 上添加标题?

【问题讨论】:

  • 你遇到了什么错误?
  • @Akash lmplot() 得到了一个意外的关键字参数“ax”。
  • @jaykodeveloper,你想为每个子图设置一个通用标题还是一个标题?
  • lmplots 不接受 ax 参数,因为它们返回 facetgrids 而不是子图。一般我只添加plt.title("your title")
  • @WoodyPride 它会生成另一个空图。不过还是谢谢

标签: python pandas matplotlib dataframe seaborn


【解决方案1】:

试试这个:

sns.lmplot(x, y, data=df, hue="hue")
ax = plt.gca()
ax.set_title("Graph (a)")

【讨论】:

  • 这会生成一个带有标题的空图; lmplot 仍未命名。
【解决方案2】:
# Create lmplot
lm = sns.lmplot(x, y, data=df, hue="hue", ax=ax)

# Access the figure
fig = lm.fig 

# Add a title to the Figure
fig.suptitle("My figtitle", fontsize=12)

【讨论】:

    【解决方案3】:
    sns.lmplot(x, y, data=df, hue="hue", ax=ax).fig.suptitle("Graph (a)")
    

    【讨论】:

    • 完美!正是我想要的!
    【解决方案4】:

    seaborn 在后台使用matplotlib,所以如果你想要一个简单的答案,请使用:

    plt.title('My Title')
    

    就在之前

    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-21
      • 2017-07-13
      • 2020-12-10
      • 2015-07-01
      • 2020-11-09
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      相关资源
      最近更新 更多