You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Matplotlib inset_zoom连接线自定义问题求助

Matplotlib inset_zoom连接线自定义问题求助

我是Python编程与绘图新手,在使用Matplotlib的inset_zoom功能时遇到两个连接线自定义难题:

  • 已成功修改连接线的线型与线宽,但设置set_visible(False)的连接线未隐藏,反而以原始样式显示;
  • 希望连接线连接矩形平行边端点而非对应顶点(详见附图)。

这些图表用于本科毕业论文,时间紧迫,恳请帮忙!

代码片段

#inset axes
x1,x2,y1,y2 = 0, 0.2, 0, 0.2 # subregion of origanal image
axin1 = ax[1].inset_axes([0.56, 0.04, 0.4, 0.4], xlim=(x1,x2), ylim=(y1,y2), xticks=[], yticks=[], xticklabels=[], yticklabels=[])

axin1.plot(x_H2_real_test, x_H2_pred_test, '.', markersize = 4)
axin1.plot(x_NH3_real_test, x_NH3_pred_test, '.', markersize = 4)
axin1.plot([0, 1], [0, 1], "-", color = 'crimson',lw=1,zorder=1 )
axin1.plot([bounds[0],bounds[1]], [bounds[0] * 1.1, bounds[1] * 1.1], "k--", lw=1)
axin1.plot([bounds[0],bounds[1]], [bounds[0] * 0.9, bounds[1] * 0.9], "k--", lw=1)

box, c1 = ax[1].indicate_inset_zoom(axin1, edgecolor="black", alpha=1,lw=0.7)
c1[0].set_visible(False)
c1[1].set_visible(True)
c1[2].set_visible(True)
c1[3].set_visible(False)
ax[1].indicate_inset_zoom(axin1, edgecolor="black", alpha=1,lw=0.7)
plt.setp([c1[:]], linestyle=":", lw=0.7)

#plt.legend()
#fig.suptitle("Parity Plot")
plt.tight_layout()
plt.show()

当前效果图

当前效果图

期望连接线位置

期望连接线位置

内容的提问来源于stack exchange,提问作者Pukah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:22:15