matplotlib PyQt5 nivigationBar 中pan和zoom功能的探索
为matplotlib生成的图添加编辑条,我们导入NavigationToolbar2QT
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
继承关系:
其中,NavigationToolbar2是实现NavigationToolbar2QT有关编辑条的主要实现类,下面对NavigationToolbar2进行详细分析。
涉及zoom功能的有四个函数: zoom(), press_zoom(), drag_zoom(), release_zoom()
涉及pan功能的四个函数与之类似.
zoom()
鼠标按下事件绑定 press_zoom(),鼠标释放事件绑定release_zoom()
press_zoom()
判断是鼠标左键还是右键触发的点击事件,存入self._button_pressed中(1: 左键;2: 右键)。
关键代码分析: 将鼠标点击的坐标(x, y)、figure中的axes对象,i(含义不明), axes对象的rect(xmin, xmax, ymin, ymax)append(添加)到self._xypress中,代码如下:
self._xypress.append((x, y, a, i, a._get_view()))
鼠标点击事件绑定_switch_on_zoom_mode()以确认zoom缩放模式(左键缩小/右键放大)
鼠标拖动事件绑定drag_zoom()
鼠标释放事件绑定_switch_off_zoom_mode()清除zoom缩放模式的设置
drag_zoom()
读取self._xypress中的记录(press_zoom中有详细参数介绍),限制绘制区域(不超出Axes对象)
根据读取的参数绘制矩形区域,
self.draw_rubberband(event, x1, y1, x2, y2)
release_zoom()
取消press_zoom()中注册的事件,移除drag_zoom()中绘制的矩形
添加功能: 无视5像素之下的zoom操作,检测共享xy轴的图形
根据self._button_pressed设置in/out(缩放/放大)
关键代码分析: 绘制一个指定的axes区域;参数: [lastx], [lasty]: press(按下)的坐标;[x], [y]: release(释放鼠标)的坐标;[direction]:‘in’: 左键,‘out’:右键;
[self._zoom_mode]: ‘x’:x方向,‘y’:y方向;[twinx], [twiny]: 关于共享坐标轴的图像显示(未深入研究)。
a._set_view_from_bbox((lastx, lasty, x, y), direction,self._zoom_mode, twinx, twiny)
Other method:
push_current(): Push the current view limits and position onto the stack
save_figure(): Save the current figure.(override require)
draw(): Redraw the canvases, update the locators.
set_message(): Display a message on toolbar or in status bar.
back(), forward(): move back/forward up the view lim stack
home(): Restore the original view. set_history_buttons(): Enable or disable the back/forward button.
press(): Called whenever a mouse button is pressed.
draw_rubberband(self, event, x0, y0, x1, y1), remove_rubberband(): Draw/Remove a rectangle rubberband to indicate zoom limits (not guaranteed that ``x0 <= x1`` and ``y0 <= y1`)
最新文章
- react+redux官方实例TODO从最简单的入门(1)-- 前言
- 2015ACM/ICPC亚洲区长春站
- SSL构建单双向https认证
- (一)学习CSS之z-index属性
- struts2+jsp+jquery+Jcrop实现图片裁剪并上传
- SQL 语句修改列名 属性 默认值
- Mvc4.0添加商品到Cookie
- python笔记之列表与元组函数和方法使用举例
- Python-老男孩-02_装饰器_面向对象_封装_继承_异常_接口_数据库
- 2019-03-23 shell练习,日志统计
- ssh远程登陆脚本(带跳板机)
- get通配符
- POJ - 3278 Catch That Cow bfs 线性
- 20165237 2017-2018-2 《Java程序设计》第3周学习总结
- Django_Form验证(二),ajax验证
- Java调整JVM内存大小——(八)
- 【CLR】详解CLR中的程序集
- Memory Controller
- 面试题一:linux面试题
- VS添加节点
热门文章
- DOTNET CORE源码分析之IServiceProvider、ServiceProvider、IServiceProviderEngine、ServiceProviderEngine和ServiceProviderEngineScope
- Vulnhub 靶场 Dijnn WP
- Natas22 Writeup(header重定向、burp截取抓包)
- asp.net core 3.1 引用的元包dll版本兼容性问题解决方案
- Journal of Proteome Research | iHPDM: In Silico Human Proteome Digestion Map with Proteolytic Peptide Analysis and Graphical Visualizations(iHPDM: 人类蛋白质组理论酶解图谱的水解肽段分析和可视化展示)| (解读人:邓亚美)
- ArrayList,HashSet,SortedSet之间的区别是什么?
- spring boot devtools热部署
- 告别炼丹,Google Brain提出强化学习助力Neural Architecture Search | ICLR2017
- xheditor图片上传
- VScode+phpStudy搭建php代码调试环境