Numpy 在seaborn jointplot中自定义轴标签

Numpy 在seaborn jointplot中自定义轴标签,numpy,matplotlib,seaborn,Numpy,Matplotlib,Seaborn,我似乎陷入了一个相对简单的问题,但在搜索了最后一个小时并进行了大量实验后,我无法解决它 我有两个numpy数组x和y,我正在使用seaborn的jointplot绘制它们: sns.jointplot(x, y) 现在我想分别将xaxis和yaxis标记为“X轴标签”和“Y轴标签”。如果我使用plt.xlabel,标签将转到边际分布。如何使它们显示在关节轴上 sns.jointplot返回一个对象,该对象允许您访问matplotlib轴,然后您可以从那里进行操作 import seaborn

我似乎陷入了一个相对简单的问题,但在搜索了最后一个小时并进行了大量实验后,我无法解决它

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

sns.jointplot(x, y)

现在我想分别将xaxis和yaxis标记为“X轴标签”和“Y轴标签”。如果我使用
plt.xlabel
,标签将转到边际分布。如何使它们显示在关节轴上

sns.jointplot
返回一个对象,该对象允许您访问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()


(您尝试的问题是,
plt.xlabel(“text”)
等函数在当前轴上运行,而当前轴不是
sns.jointplot
中的中心轴;但面向对象的接口更具体地说明它将在哪些轴上运行)。

或者,您可以在调用
jointplot
的过程中指定数据框中的轴标签

import pandas as pd
import seaborn as sns

x = ...
y = ...
data = pd.DataFrame({
    'X-axis label': x,
    'Y-axis label': y,
})
sns.jointplot(x='X-axis label', y='Y-axis label', data=data)