如何在python中通过命令行激活'Zoom to rectangle'?

How to activate 'Zoom to rectangle' by command line in python?

在 pyplot 中,我通常绘制大量数据,因此,总是使用 ZOOM(通过按 'Zoom to rectangle' 按钮,总是这样做有点麻烦)。 python有没有办法通过命令行激活缩放功能?已经搜索了很多,但没有运气。我希望这样的事情成为可能:

plt.pyplot(X,Y) # plot some data
plt.zoom_activate() # !! activate the 'Zoom to rectangle' - that's what Im looking for
plt.show() # show the pyplot

您要查找的命令是

fig.canvas.toolbar.zoom()

如果fig是一个matplotlib图形。