首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在seaborn jointplot中自定义轴标签

在seaborn jointplot中自定义轴标签
EN

Stack Overflow用户
提问于 2018-03-02 17:05:04
回答 2查看 24.9K关注 0票数 23

我似乎被一个相对简单的问题卡住了,但在过去一个小时的搜索和大量的实验之后,我无法解决它。

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

代码语言:javascript
复制
sns.jointplot(x, y)

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-02 19:58:54

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

代码语言:javascript
复制
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中的中心轴;但是面向对象的接口更具体地说明它将在什么上操作)。

票数 47
EN

Stack Overflow用户

发布于 2018-05-08 02:17:09

或者,可以在对jointplot的调用中指定pandas DataFrame中的轴标签。

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49065837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档