Pyplot交互式缩放 [英] Pyplot Interactive Zooming

查看:81
本文介绍了Pyplot交互式缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示第一次显示时放大的图像,但仍然可以使用图形工具栏中的交互式重置原始视图"按钮缩小到全比例.裁剪是完全不可接受的.使用 plt.axis([x0,x1,y0,y1])确实允许平移,但交互式窗口不会重置为完整比例.

I want to display an image that is zoomed in when first shown, but still has the ability to zoom out to the full scale using the interactive "Reset original view" button in the figure toolbar. Cropping is completely unacceptable. Using plt.axis([x0, x1, y0, y1]) does allow panning but the interactive window will not reset to full scale.

有没有办法触发情节放大或以另一种方式解决这个问题?

Is there a way to trigger the plot to zoom or solve this issue another way?

推荐答案

一种方法是:

fig, ax = plt.subplots(1, 1)
ax.imshow(np.random.rand(20, 20)
fig.canvas.toolbar.push_current()  # save the 'un zoomed' view to stack
ax.set_xlim([5, 10])
ax.set_ylim([5, 10])
fig.canvas.toolbar.push_current()  # save 'zoomed' view to stack

我不确定私有 push_current 是如何考虑的,正如我在评论中所说的,这是针对 1.5 重构的(

I am not sure how private push_current is considered and as I said in the comments this is being refactored for 1.5 (https://github.com/matplotlib/matplotlib/wiki/Mep22).

请参见 https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_bases.py#L2600 了解如何实现平移/缩放.没有'zoom_window'命令的原因是用于静态图像,您只需使用 set_ * lim .

See https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_bases.py#L2600 for how pan/zoom are implemented. The reason there isn't a 'zoom_window' command is for static images, you just use set_*lim.

这篇关于Pyplot交互式缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆