我似乎被一个相对简单的问题卡住了,但在过去一个小时的搜索和大量的实验之后,我无法解决它。
我有两个numpy数组x和y,我正在使用seaborn的jointplot来绘制它们:
sns.jointplot(x, y)现在我想将x轴和yaxis分别标记为“X轴标签”和“Y轴标签”。如果我使用plt.xlabel,标签就是边缘分布。如何使它们显示在关节轴上?
发布于 2018-03-02 19:58:54
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()

(您尝试的问题是,像plt.xlabel("text")这样的函数在当前轴上操作,而当前轴不是sns.jointplot中的中心轴;但是面向对象的接口更具体地说明它将在什么上操作)。
发布于 2018-05-08 02:17:09
或者,可以在对jointplot的调用中指定pandas DataFrame中的轴标签。
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)https://stackoverflow.com/questions/49065837
复制相似问题