奇妙双子力量“缩放到矩形”激活?

7 投票
1 回答
1166 浏览
提问于 2025-04-17 06:24

在这里输入图片描述

有没有办法让“矩形缩放”工具在显示matplotlib图形时默认自动激活呢?

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-300, 300)
y = x**2-7*x
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot(x, y)
# Add something here to activate the "Zoom to rectangle" tool?
plt.show()

1 个回答

5

这个对我有效:

plt.get_current_fig_manager().toolbar.zoom()

撰写回答