matplotlib inset_axis 内部轴放置导致刻度标签与父轴重叠

1 投票
1 回答
3834 浏览
提问于 2025-04-20 18:45

当我使用 inset_axes 在图中放置一个小图时,如果图的尺寸很小,小图的刻度标签会和坐标轴的边框重叠。有没有办法让图自动调整,避免这个问题呢?

代码:

fig, ax1 = plt.subplots()

ax1.plot(dd1["mag"].index, dd1["mag"], '.-',label="$\omega$")
ax1.plot(newindex,curvy1,'--', label="${0:.3f} \cdot I$".format(popt1[0]))
ax1.set_xlim((5e11, 5e13))
ax1.set_ylim((2e-7,.25e-4))

ax1_inset = inset_axes(ax1, width="40%", height="40%", loc=4)
ax1_inset.plot(dd1["mag"].index, (one - np.array(dd1["mag"]))/one)
ax1_inset.plot(dd1["mag"].index, map(lambda x: -.01, dd1["mag"].index), ':')
ax1_inset.set_xlim(5e11,5e13)
ax1_inset.set_ylim(-.1,.05)
ax1_inset.set_xscale("log")

使用的 matplotlibrc 设置:

matplotlib.rcParams['figure.figsize'] = '4,3'

matplotlib.rcParams['axes.formatter.use_mathtext'] = 'True'
matplotlib.rcParams['axes.formatter.useoffset'] = 'False'

matplotlib.rcParams['figure.subplot.left'] = .22
matplotlib.rcParams['figure.subplot.right'] = .95
matplotlib.rcParams['figure.subplot.bottom'] = .20
matplotlib.rcParams['figure.subplot.top'] = .90

示例图

1 个回答

-1

这个叫“borderpad”的参数好像可以解决这个问题。

撰写回答