2024-10-06 13:32:10 发布
网友
Seaborn默认情况下在主图的顶部和右侧绘制边际分布图。是否可以更改此位置(例如,到底部和左侧)?在
一个最小的例子,使用seaborn文档:
tips = sns.load_dataset("tips") g = sns.jointplot(x="total_bill", y="tip", data=tips)
给予。。。在
这有点乏味,但您可以根据需要调整this example。它使用make_axes_locatable分隔符。从上到下和从右到左更改此设置没有问题,但是您需要更改所有轴上的标签和记号。在
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()
这有点乏味,但您可以根据需要调整this example。它使用
make_axes_locatable
分隔符。从上到下和从右到左更改此设置没有问题,但是您需要更改所有轴上的标签和记号。在相关问题 更多 >
编程相关推荐