matplotlib窗口状态管理(最大化、最小化、全屏、置顶、控制按钮,基于PyQT5后端)

PyQt5中嵌入matplotlib QtDesigner+matplotlib实现GUI界面绘制柱状图 阅读详情
AI摘要

本文介绍如何使用Matplotlib结合PyQT5实现图形界面窗口状态管理,包括最大化、最小化、全屏显示、置顶及自定义窗口控制按钮等功能。

使用matplotlib绘图时,通常利用matplotlib.pyplot模块的show函数(即常用的plt.show())显示绘图结果,显示的方式是通过后端创建窗口容纳绘图图像,matplotlib支持多种后端,各种后端的实现有所差异,因此matplotlib绘图窗口的状态管理与后端的具体实现息息相关。
在此以PyQT5后端为例,简要演示matplotlib窗口状态切换。

原理

查看源码可知,与matplotlib窗口状态相关源码定义在matplotlib.backends.backend_qt5模块的FigureManagerQT类当中,与窗口状态相关的方法实现均依赖于window属性(即figure.canvas.manager.window),而window属性是PyQT5中QMainWindow类的实例。
在matplotlib中,仅定义了全屏切换full_screen_toggle()方法的实现,未定义窗口最大化、最小化、置顶等实现,根据PyQT5相关知识,窗口状态切换的重要定义如下:

  • 窗口全屏
    figure .canvas.manager.window.showFullScreen()
  • 窗口最大化
    figure .canvas.manager.window.showMaximized()
  • 窗口最小化
    figure .canvas.manager.window.showMinimized()
  • 窗口正常状态
    figure .canvas.manager.window.showNormal()
  • 窗口置顶
    fig.canvas.manager.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
  • 自定义窗口控制按钮(仅显示关闭按钮)
    fig.canvas.manager.window.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowCloseButtonHint)

在窗口置顶和控制按钮实现中,需要使用setWindowFlags方法,其参数为WindowType,在QT中为枚举类型(enum),具体取值参考https://www.riverbankcomputing.com/static/Docs/PyQt5/api/qtcore/qt.html#WindowType。

案例

功能:以工具栏工具按钮形式调用窗口状态管理方法。
在这里插入图片描述

from matplotlib.backend_tools import ToolBase, ToolToggleBase
import matplotlib.pyplot as plt
from PyQt5 import QtCore

plt.rcParams['toolbar'] = 'toolmanager'


class showMax(ToolToggleBase):
    description = '最大化切换'

    def enable(self, *args, **kwargs):
        fig
【Spinning up】2.1、将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen) 将Matplotlib自动全屏显示和保存图像(Saving Matplotlib graphs to image as full screen) 前言: 每次matplotlib画图都是一个小图,然后手动调整为全屏,再手动调整图片的位置,简直恶心透了。 今天趁机将自动全屏的问题解决了。 参考链接: 将Matplotlib图形保存为全屏图像(Saving Matplotlib graphs to image as full screen) 解决方案 The method you use to maximis 阅读详情

相关推荐

深入PyQt5:matplotlib窗口状态管理的实战技巧(最大化、最小化、全屏与置顶)

本文深入探讨了PyQt5与matplotlib结合时的窗口状态管理技巧,包括最大化、最小化、全屏与置顶等核心功能。通过实战代码示例,展示了如何智能切换窗口状态、优化全屏交互、实现后台处理及多窗口协同控制,帮助开发者提升数据可视化应用的交互体验。

qq_27496129的博客 286

避坑指南:Matplotlib+PyQt5窗口控制那些奇葩问题(最大化闪退/置顶失效)

本文深入探讨了Matplotlib与PyQt5结合时遇到的窗口状态管理难题,如最大化闪退和置顶失效。文章分析了底层原理,提供了跨平台的稳健解决方案和诊断工具,帮助开发者有效规避这些常见陷阱,提升GUI应用的稳定性与用户体验。

weixin_29053577的博客 321

Python打字练习工具:从零构建项目驱动学习实战

在编程学习中,项目驱动是巩固语法、提升工程思维的有效方法。其原理在于通过构建具体应用,将抽象概念转化为可运行的代码,实现从理论到实践的闭环。这种学习方式的技术价值在于能提供即时反馈,帮助开发者深化对核心概念的理解,并锻炼解决实际问题的能力。常见的应用场景包括开发实用工具、游戏或自动化脚本,以提升打字速度、代码手感及算法熟练度。本文以Python打字练习工具为例,拆解如何利用字符串处理、列表操作及GUI开发等热词技术,构建一个可运行、可修改、可扩展的学习模板,帮助初学者和开发者通过实战掌握Python工程化思

congji3817的博客 409

JupyterNotebook 输出窗口的显示效果调整方法

主要介绍了JupyterNotebook 输出窗口的显示效果调整方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

GPU运维工程师入门指南 (第九篇): 高性能网络 - InfiniBand与RDMA技术

本文介绍了支撑AI分布式训练的高性能网络技术InfiniBand和RDMA。传统TCP/IP网络因内核开销和内存拷贝成为性能瓶颈,而InfiniBand提供高带宽、低延迟的专用网络,RDMA则通过内核旁路和零拷贝技术实现节点间内存直接访问,显著提升通信效率。特别介绍了GPUDirect RDMA技术,使GPU显存可直接通信。文章还列举了运维人员在部署这些技术时需要考虑的硬件、驱动、配置和监控等关键点。这些技术共同构成了支撑大规模AI集群的"数据高速公路",为后续讨论存储性能瓶颈奠定了基础

weixin_42587823的博客 1096

Infiniband互连网络概述

一、Infiniband是什么? InfiniBand(简称IB)是一种工业标准规范,它定义了一种输入/输出架构,用于计算节点、通信基础设施设备、存储和嵌入式系统的互连。操作系统可以是Linux、Windows或ESXI。 IB网络一共是五层,从第一天起,IB就被设计为提供一个端到端的解决方案,改善和加速从物理层到上层的所有协议层。 IB协议于2000年由IBTA(InfiniBand Trade Association)提出,其规定了一...

weixin_41687819的博客 5226

autoDL算力云装Xinference[坑与步骤]

在页面直接点击下载会出现下着下载进度条消失,试了几次才出现这个报错,现在我们就继续安装缺少的包吧。这一步成功绕开了系统盘空间限制。先租用一个合适的服务器,建议不要选最新版本,跟我选的一样即可,不然后面会出现。最近在 AutoDL 上尝试部署。🚫 不要直接使用以下命令。点击下面链接即可打开。

ngadminq的博客 2382

告别Modern Standby!Win10/11强制S3睡眠的终极指南(含BIOS设置避坑)

本文是针对Windows 10/11用户因Modern Standby(S0低电量待机)导致睡眠耗电、发热问题的终极解决方案。文章详细对比了Modern Standby与传统S3睡眠(Suspend to RAM)的本质区别,并提供了从系统诊断、注册表修改、BIOS/UEFI设置避坑到驱动优化的完整步骤,旨在帮助用户强制启用稳定、省电的S3睡眠模式,彻底告别睡眠噩梦。

n7o8p的博客 792

ALSA音频开发实战:如何用snd_pcm_avail避免缓冲区溢出(附完整代码)

本文深入探讨了在ALSA音频开发中,如何利用`snd_pcm_avail`函数有效管理环形缓冲区,从而避免音频数据溢出或下溢。通过实战代码示例,详细解析了该函数在播放场景下的核心作用,即实时查询可写入的帧数,并构建了自适应写入循环以实现稳健的流量控制,确保音频流的平滑与稳定。

weixin_29183637的博客 461

基于qiime2的16S数据分析全流程:从导入数据到下游分析一条龙

基于qiime2的16s测序数据分析分析激活qiime环境我已经把上面这句代码放在了.bashrc里面,因此激活qiime2环境只需要运行activate_qiime即可/bin/bash# 设置目录路径# 输出表头 echo -e "sample-id\tforward-absolute-filepath\treverse-absolute-filepath"# 遍历_R1和_R2文件do # 检查R1文件是否存在then# 获取样本ID(去掉_R1.fastq.gz)

2301_76771985的博客 5517

超声波雷达探测车位及信号处理方法

在APA泊车中用到了超声波雷达,第一次接触,总结研究之。

周陽讀書 1229

ArcGIS实验教程——实验十七:缓冲区分析(Buffer Analysis)

【实验描述】缓冲区(Buffer)是为了识别某一地理实体对周围地物的影响而在其周围建立的一定宽度多边形区域,缓冲区分析(Buffer Analysis)是用来确定不同地理要素的空间临近性或接近程度的一种分析方法。作为GIS的空间分析方法之一,缓冲区分析的应用范围特别广泛,常用于分析矢量实体对周围的影响。例如,工厂排放的废水废气所影响的空间范围等等。 一、缓冲区的基本概念 1、缓冲区 是地理空间目标的一种影响范围或服务范围。 2、缓冲区分析 指根据分析对象的点、线、面实体,自动建立它们周围一定距离的带

智慧空间实验室 1万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: matplotlib更改窗口图标
下一篇: matplotlib 源码解析标题实现(窗口标题,标题,子图标题不同之间的差异)
mighty13
博客等级 码龄23年 728粉丝 438原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值