默认情况下,Seaborn在主图的顶部和右侧绘制边际分布。可以更改此位置(例如,更改为底部和左侧)吗?
使用seaborn文档的一个最小示例:
tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips)
给予...
答案 0 :(得分:1)
这有点乏味,但是您可以根据自己的需要调整this example。它使用make_axes_locatable
除法器。从上到下,从右到左更改此选项都没问题,但是您需要更改所有轴上的标签和刻度。
import seaborn as sns
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
tips = sns.load_dataset("tips")
x = tips["total_bill"]
y = tips["tip"]
fig, axScatter = plt.subplots(figsize=(5.5, 5.5))
fig.subplots_adjust(.1,.1,.9,.9)
axScatter.scatter(x, y)
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("left", 1.2, pad=0.1, sharey=axScatter)
# make some labels invisible
axHistx.tick_params(labelbottom=False, bottom=False,
left=False, labelleft=False, right=True, labelright=True)
axHisty.tick_params(labelleft=False, left=False,
bottom=False, labelbottom=False, top=True, labeltop=True)
axHistx.invert_yaxis()
axHisty.invert_xaxis()
axScatter.xaxis.tick_top()
axScatter.yaxis.tick_right()
axScatter.xaxis.set_label_position('top')
axScatter.yaxis.set_label_position('right')
axScatter.set(xlabel="Total Bill", ylabel="Tip")
axHistx.hist(x, bins=16, density=True)
axHisty.hist(y, bins=16, density=True, orientation='horizontal')
plt.show()