如何为seaborn boxplot添加标题 [英] How to add title to seaborn boxplot

查看:608
本文介绍了如何为seaborn boxplot添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来很适合 Google,但一直无法在网上找到有用的东西.

Seems pretty Googleable but haven't been able to find something online that works.

我已经尝试了 sns.boxplot('Day','Count',data = gg).title('lalala') sns.boxplot('Day','Count', data= gg).suptitle('lalala').没有一个工作.我想可能是因为我也在使用 matplotlib.

I've tried both sns.boxplot('Day', 'Count', data= gg).title('lalala') and sns.boxplot('Day', 'Count', data= gg).suptitle('lalala'). None worked. I think it might be because I'm also working with matplotlib.

推荐答案

Seaborn box plot返回matplotlib轴实例.与 pyplot 本身不同,它有一个方法 plt.title(),轴的相应参数是 ax.set_title().因此,您需要致电

Seaborn box plot returns a matplotlib axes instance. Unlike pyplot itself, which has a method plt.title(), the corresponding argument for an axes is ax.set_title(). Therefore you need to call

sns.boxplot('Day', 'Count', data= gg).set_title('lalala')

一个完整的例子是:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
sns.boxplot(x=tips["total_bill"]).set_title("LaLaLa")

plt.show()

当然,您也可以使用返回的axis实例使其更具可读性:

Of course you could also use the returned axes instance to make it more readable:

ax = sns.boxplot('Day', 'Count', data= gg)
ax.set_title('lalala')
ax.set_ylabel('lololo')

这篇关于如何为seaborn boxplot添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆