【发布时间】:2014-11-05 01:17:24
【问题描述】:
当我使用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
【问题讨论】:
-
没有自动布局引擎,您必须调整位置、大小和字体大小才能使其正常工作。 IIRC
inset_axes有一个 pad kwarg。 -
@tcaswell:在答案中写下用于填充的特定 kwarg,我会接受它。这正是我想要的。
-
如果这足以让您解决问题,您可以写下答案吗?我不记得头顶的语法,今天没有足够的带宽来查找/写下来,而且我真的不需要代表。
-
@tcaswell:没关系。在回答我自己的问题之前,我想我会把它提供给你。感谢您的帮助
标签: python matplotlib insets multiple-axes