在seaborn jointplot中自定义轴标签

Pea*_*ful 10 numpy matplotlib seaborn

我似乎陷入了一个相对简单的问题但是在搜索了最后一小时并经过大量实验之后无法修复它.

我有两个numpy数组x,y我正在使用seaborn的联合图来绘制它们:

sns.jointplot(x, y)
Run Code Online (Sandbox Code Playgroud)

现在我想分别将x轴和y轴标记为"X轴标签"和"Y轴标签".如果我使用plt.xlabel,标签将进入边际分布.如何让它们出现在关节轴上?

Bon*_*fum 17

sns.jointplot返回一个JointGrid对象,它允许您访问matplotlib轴,然后您可以从那里进行操作.

import seaborn as sns
import numpy as np

#example data
X = np.random.randn(1000,)
Y = 0.2 * np.random.randn(1000) + 0.5

h = sns.jointplot(X, Y)

# JointGrid has a convenience function
h.set_axis_labels('x', 'y', fontsize=16)

# or set labels via the axes objects
h.ax_joint.set_xlabel('new x label', fontweight='bold')

# also possible to manipulate the histogram plots this way, e.g.
h.ax_marg_y.grid('on') # with ugly consequences...

# labels appear outside of plot area, so auto-adjust
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)

seaborn jointplot与自定义标签

(与您的尝试的问题是,功能,如plt.xlabel("text")在当前轴,这是不是在sns.jointplot中央一操作;但面向对象的接口是更具体的,以什么它将上操作).