首页 > 解决方案 > Matplotlib:创建与父轴不同的脊椎的 zoomed_inset_axis

问题描述

我有一个带有 zoomed_inset_axis 对象的图,如 https://matplotlib.org/3.1.1/_images/sphx_glr_inset_locator_demo2_001.png所示

现在我希望我的父轴对象以某种方式被指定,所以右脊椎不可见。但是,如果我这样做,我的放大插图也会以相同的方式进行,这是我不想要的。我认为发生这种情况是因为它以轴对象为父对象。

有什么办法可以改变吗?基本上我想要一个被“正常”框包围的被诅咒的父对象和一个放大的插图。

我试过seabon.despine(fig=fig, ax=ax)了,但这也让我放大了对象。我也试过ax.spines['right'].set_visible=False了,但这也鄙视我的缩放对象

fig, ax = plt.subplots(1,1)
axins = zoomed_inset_axes(ax, 7, loc=4)
seaborn.despine(fig=fig,ax=ax, offset=10)

标签: pythonmatplotlibseaborn

解决方案


以下两项均按预期工作:

海伯恩的绝望

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
import seaborn as sns

fig, ax = plt.subplots(1,1)
axins = zoomed_inset_axes(ax, .5, loc=4)

sns.despine(ax=ax, offset=10)

plt.show()

matplotlib 的脊椎可见性

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes

fig, ax = plt.subplots(1,1)
axins = zoomed_inset_axes(ax, .5, loc=4)

ax.spines['right'].set_visible(False)

plt.show()

推荐阅读