且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Matplotlib 处理渐近线/不连续性

更新时间:2023-02-26 22:18:40

这可能不是您正在寻找的优雅解决方案,但如果只想要大多数情况下的结果,您可以剪裁"绘制的大值和小值数据分别为+∞-∞.Matplotlib 不绘制这些.当然,您必须小心不要将分辨率设置得太低或剪辑阈值太高.

This may not be the elegant solution you are looking for, but if just want results for most cases, you can "clip" large and small values of your plotted data to +∞ and -∞ respectively. Matplotlib does not plot these. Of course you have to be careful not to make your resolution too low or your clipping threshold too high.

utol = 100.
ltol = -100.
yy = 1/(xx-2)
yy[yy>utol] = np.inf
yy[yy<ltol] = -np.inf

ax.plot(xx, yy, zorder=100, linewidth=3, color='red')