Python Seaborn Facetgrid更改xlabels [英] Python Seaborn Facetgrid change xlabels

查看:188
本文介绍了Python Seaborn Facetgrid更改xlabels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just can't figure out how to change the xlabels in a Seaborn Facetgrid. It offers a method for changing the x labels with set_xlabels() but unfortunately not individually for each subplot.

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

I have two subplots which share the y-axis but have a different x-axes and i want to label them with different texts.

有人可以给我一个提示吗?预先谢谢你.

Can anybody give me a hint. Thank you in advance.

推荐答案

您可以使用axes属性访问FacetGrid的各个轴,然后在每个轴上使用set_xlabel().例如:

You can access the individual axes of the FacetGrid using the axes property, and then use set_xlabel() on each of them. For example:

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)(一行,两列).

Note in this example, g.axes has a shape of (1,2) (one row, two columns).

这篇关于Python Seaborn Facetgrid更改xlabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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