- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在带有插图轴的图中,我想使用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 标记插图。但是,我在控制 zorder 和标记插入的结果线的剪裁时遇到了麻烦。插入轴设置为 zorder=4
,我正在使用:
fig = plt.figure()
fig.set_tight_layout(False)
ax = fig.gca()
x = np.arange(4500.0, 10000.0)
ax.plot(x, 700-x/20.0+20*np.sin(x/8.0), label="Skylines")
from mpl_toolkits.axes_grid1.inset_locator import InsetPosition, mark_inset, inset_axes
inset_ax = fig.add_axes([0,0,1,1], zorder=4, frameon=True)
inset_ax.set_axes_locator(InsetPosition(ax, [0.1, 0.1, 0.4, 0.5]))
inset_ax.plot(x, 700-x/20.0+20*np.sin(x/8.0))
inset_ax.set_xlim(8800, 8850)
inset_ax.set_ylim(230, 285)
# inset_ax.set_ylim(100, 600)
mark_inset(ax, inset_ax, loc1=2, loc2=3, linewidth=0.7, fc="None", ec='k', alpha=0.4, clip_on=True, zorder=3)
ax.axhline(y=300, c='r', label="Test")
leg = ax.legend(ncol=1, loc='upper center', frameon=True, framealpha=1.0)
leg.set_zorder(5)
plt.show()
对于 y 限制中的两种不同情况,结果为
这里不需要的行为是插入线分别出现在插入轴上(而标记为 Test 的线很好地放在插入轴后面)和主轴外部(并穿过图例)。我原以为 zorder
和 clip_on
参数可以解决这个问题,但它们似乎没有效果。
最佳答案
案例一
zorder
是在每个轴基础上计算的。由于连接线已添加到插图轴,因此它们将始终位于轴背景的顶部。一种选择是将它们从插入轴中移除并将它们添加到原始轴中。
案例二
连接器在 matplotlib 源代码中明确没有被剪裁,因为作为插入轴的一部分,您永远不希望它们被插入轴剪掉。
但是,如果它们是原始轴的一部分,您可以再次将裁剪设置为打开。
总计
ret = mark_inset(ax, inset_ax, loc1=2, loc2=3, linewidth=0.7, fc="None", ec='k', alpha=0.4)
for bc in ret[1:]:
bc.remove()
ax.add_patch(bc)
bc.set_zorder(4)
bc.set_clip_on(True)
关于python - 如何使用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 控制 zorder 和裁剪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56932448/
假设我想将绘图插入到图形中,但插入图的轴范围与我标记插入的轴范围不同。例如: fig, ax = plt.subplots() axins = inset_axes(ax, 1,1 , loc=2,
这个解释起来有点棘手。基本上,我想制作一个插图,然后利用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 的便利性,但我希望插图中的数据完全独立于父轴
我想在一个子图中绘制阻尼随机游走的时间序列,然后在第二个子图中放大它。我知道来自 matplotlib 的 mark_inset,它工作正常。到目前为止我的代码是: from mpl_toolkits
我有这个代码 ax = plt.subplot(222) plt.plot(time_list, data[1], color='red') plt.plot(time_list, y_offset,
我正在尝试使用带有插图缩放功能的 matplotlib 绘制绘图。我发现以下示例将生成带有插图的图: import matplotlib.pyplot as plt from mpl_toolkits
在带有插图轴的图中,我想使用 mpl_toolkits.axes_grid1.inset_locator.mark_inset 标记插图。但是,我在控制 zorder 和标记插入的结果线的剪裁时遇到了
我是一名优秀的程序员,十分优秀!