python中Matplotlib库显示界面中进行鼠标交互绘制操作
来源:互联网 发布:php技术文档模板 编辑:程序博客网 时间:2024/06/05 10:47
近期在用Python做医学图像处理系统制作,逐步跟大家分享我遇到的问题以及解决方案。今天来跟大家说一下在matplotlib库显示界面中进行鼠标交互绘制等操作。
先上图,下图为用matplotlib进行显示的脊柱图像(.dicom格式),后期跟大家介绍.dicom文件的读取以及相应图像处理方式。
本文要做的就是在此界面用鼠标进行交互绘制操作。
#鼠标事件def OnClick(event): global Coords1x,Coords1y global Coords3x,Coords3y #ax = plt.gca() if event.button ==1: Coords1x = event.xdata Coords1y = event.ydata if event.button == 3: Coords3x = event.xdata Coords3y = event.ydatadef OnMouseMotion(event): global Coords2x,Coords2y,x1,y1 if event.button == 1: Coords2x = event.xdata Coords2y = event.ydata x1 = [Coords1x,Coords2x] y1 = [Coords1y,Coords2y] ax = plt.gca() lines = ax.plot(x1,y1,picker = 20) ax.figure.canvas.draw() #删除之前的线条,进行更新 l = lines.pop(0) l.remove() del l elif event.button == 3: Coords4x = event.xdata Coords4y = event.ydata x2 = [Coords3x,Coords4x] y2 = [Coords3y,Coords4y] ax1 = plt.gca() #lines = ax1.plot(x1,y1,picker = 5) lines1 = ax1.plot(x2,y2,picker = 20) ax1.figure.canvas.draw() #删除之前的线条,进行更新 l = lines1.pop(0) l.remove() del l
##关联鼠标点击事件 fig.canvas.mpl_connect('button_press_event',OnClick) fig.canvas.mpl_connect('motion_notify_event',OnMouseMotion)
完成绘制操作
阅读全文
0 0
- python中Matplotlib库显示界面中进行鼠标交互绘制操作
- python中matplotlib绘制图形
- python中matplotlib绘制图形
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib画图中文不能显示
- python matplotlib中显示中文问题
- Python图表绘制库Matplotlib学习(一)显示窗口
- python matplotlib从文件中读取数据绘制散点图
- python matplotlib从文件中读取数据绘制折线图
- Python中Matplotlib绘图
- python中安装matplotlib
- Python中matplotlib画图
- Python 中利用 matplotlib 进行曲线的部分填充 fill_betweenx
- 解决python中matplotlib绘图中文显示问题
- 19纯虚函数和抽象类
- Ubuntu下使用Pylon相机
- iOS 视频录制 包括预览图片与视频还有写入自己自定义的App相册 微信小视频
- R-CNN,SPP-NET, Fast-R-CNN,Faster-R-CNN, YOLO,系列深度学习检测方法
- 网络---端口
- python中Matplotlib库显示界面中进行鼠标交互绘制操作
- Gilde加载图片
- 多彩烟花
- P1996 约瑟夫问题
- 高性能MYSQL(查询优化)
- 微服务,够了 (对微服务的一些客观正名和经验指导)
- springboot整合springSecurity出现的问题,post,delete,put无法使用
- ios 判断当前页面从哪个页面跳转过来的(上个界面是哪个ViewController)
- [PPPOE]PPPD源码分析