『Python』matplotlib实现GUI效果
1. 类RadioButtons的使用方法
类似单选框
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.widgets import RadioButtons
mpl.use("Qt5Agg")
x = np.linspace(0.0, 2.0, 1000)
y1 = 1.5 * np.cos(2 * np.pi * x)
y2 = 1.0 * np.cos(2 * np.pi * x)
y3 = 0.8 * np.cos(2 * np.pi * x)
fig, ax = plt.subplots(1, 1)
line, = ax.plot(x, y1, color="red", lw=2)
plt.subplots_adjust(left=0.35)
facecolor = "cornflowerblue"
ax1 = plt.axes([0.1, 0.7, 0.15, 0.15], facecolor=facecolor)
radio1 = RadioButtons(ax1, ("1.5A", "1.0A", "0.8A"))
def amplitudefunc(label):
hzdict = {"1.5A": y1, "1.0A": y2, "0.8A": y3}
ydata = hzdict[label]
line.set_ydata(ydata)
plt.draw()
radio1.on_clicked(amplitudefunc)
ax2 = plt.axes([0.1, 0.4, 0.15, 0.15], facecolor=facecolor)
radio2 = RadioButtons(ax2, ("red", "green", "orange"))
def colorfunc(label):
line.set_color(label)
plt.draw()
radio2.on_clicked(colorfunc)
ax3 = plt.axes([0.1, 0.1, 0.15, 0.15], facecolor=facecolor)
radio3 = RadioButtons(ax3, ("-", "--", "-.", ":"))
def linestylefunc(label):
line.set_linestyle(label)
plt.draw()
radio3.on_clicked(linestylefunc)
plt.show()

2. 类Cursor的使用方法
帮你聚焦鼠标所在位置
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.widgets import Cursor
lineprops = dict(color="red", lw=2)
fig, ax = plt.subplots(1, 1, subplot_kw=dict(facecolor="lemonchiffon"))
x = np.random.random(100)
y = np.random.random(100)
ax.scatter(x, y, marker="o")
ax.set_xlim(-0.02, 1.02)
ax.set_ylim(-0.02, 1.02)
cursor = Cursor(ax, useblit=True, **lineprops) # 必须接收,不然会自动销毁掉。。。
plt.show()

3. 类CheckButtons的使用方法
类似复选框
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.widgets import CheckButtons
x = np.linspace(0.0, 2.0, 1000)
y1 = 1.5 * np.cos(2 * np.pi * x)
y2 = 1.0 * np.cos(2 * np.pi * x)
y3 = 0.8 * np.cos(2 * np.pi * x)
fig, ax = plt.subplots(1, 1)
line1, = ax.plot(x, y1, color="red", lw=2, visible=False, label="1.2 A")
line2, = ax.plot(x, y2, color="green", lw=2, visible=False, label="1.0 A")
line3, = ax.plot(x, y3, color="orange", lw=2, visible=False, label="0.8 A")
plt.subplots_adjust(left=0.30)
facecolor = "cornflowerblue"
cax = plt.axes([0.1, 0.4, 0.1, 0.15], facecolor=facecolor)
lines = [line1, line2, line3]
labels = [str(line.get_label()) for line in lines]
visibility = [line.get_visible() for line in lines]
check = CheckButtons(cax, labels, visibility)
def func(label):
index = labels.index(label)
lines[index].set_visible(not lines[index].get_visible())
plt.draw()
check.on_clicked(func)
plt.show()

『Python』matplotlib实现GUI效果的更多相关文章
- 『Python』matplotlib实现动画效果
一般而言,在绘制复杂动画时,主要借助模块animation来完成 import numpy as np import matplotlib.pyplot as plt import matplotli ...
- 『Python』matplotlib常用函数
1. 绘制图表组成元素的主要函数 1.1 plot()--展现量的变化趋势 import numpy as np import matplotlib.pyplot as plt import matp ...
- 『Python』matplotlib的imshow用法
热力图是一种数据的图形化表示,具体而言,就是将二维数组中的元素用颜色表示.热力图之所以非常有用,是因为它能够从整体视角上展示数据,更确切的说是数值型数据. 使用imshow()函数可以非常容易地制作热 ...
- 『Python』matplotlib坐标轴应用
1. 设置坐标轴的位置和展示形式 import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.use ...
- 『Python』matplotlib共享绘图区域坐标轴
1. 共享单一绘图区域的坐标轴 有时候,我们想将多张图形放在同一个绘图区域,不想在每个绘图区域只绘制一幅图形.这时候,就可以借助共享坐标轴的方法实现在一个绘图区域绘制多幅图形的目的. import n ...
- 『Python』matplotlib划分画布的主要函数
1. subplot() 绘制网格区域中几何形状相同的子区布局 函数签名有两种: subplot(numRows, numCols, plotNum) subplot(CRN) 都是整数,意思是将画布 ...
- 『Python』matplotlib常用图表
这里简要介绍几种统计图形的绘制方法,其他更多图形可以去matplotlib找examples魔改 1. 柱状图 柱状图主要是应用在定性数据的可视化场景中,或是离散数据类型的分布展示.例如,一个本科班级 ...
- 『Python』matplotlib初识
1. 核心原理 使用matplotlib绘图的原理,主要就是理解figure(画布).axes(坐标系).axis(坐标轴)三者之间的关系. 下面这幅图更详细: 以"美院学生张三写生画画&q ...
- 『Python』__getattr__()特殊方法
self的认识 & __getattr__()特殊方法 将字典调用方式改为通过属性查询的一个小class, class Dict(dict): def __init__(self, **kw) ...
随机推荐
- NOIP 模拟 $14\; \text{抛硬币}$
题解 \(by\;\;zj\varphi\) 签到题,自己看题解 Code #include<bits/stdc++.h> #define ri register signed #defi ...
- 第一次上传代码到gitee
初始化 git init 添加文件到本地仓库 git add . 提交文件到本地仓库 git remote add origin 仓库地址 拉去远程仓库代码 git pull origin maste ...
- 常用正则表达式最强汇总(含Python代码举例讲解+爬虫实战)
大家好,我是辰哥~ 本文带大家学习正则表达式,并通过python代码举例讲解常用的正则表达式 最后实战爬取小说网页:重点在于爬取的网页通过正则表达式进行解析. 正则表达式语法 Python的re模块( ...
- Qt 中的属性系统(Property System)
21 人赞同了该文章 本节内容主要讲解我对 Qt 属性系统的理解.官方文档参考 The Property System. 如何理解"属性系统"这个概念? 一般我们说一个类有什么属性 ...
- git push&pull命令详解
git pull的作用是从一个仓库或者本地的分支拉取并且整合代码. git pull [<options>] [<repository> [<refspec>-] ...
- GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组
1 drop table orders; 2 create table orders ( 3 o_id int auto_increment primary key, 4 orderdate date ...
- mzy,struts学习(三):action中获得servlet中三域一参的三种方法
package com.mzy.servlet; import java.util.Arrays; import java.util.Map; import javax.servlet.Servlet ...
- HuaWeiJava 上机
1 /* 2 * 第二题,输入字符串长度,字符串,计数m.从前往后计数,当数到m个元素时,m个元素出列,同时将该元素赋值给m, 3 * 然后从下一个数计数循环,直到所有数字都出列,给定的数全部为大于0 ...
- vmware 配置不同网段双网卡。
一.前言 需求:由于LVS演练需要,需要配置两张linux OS网卡,而且是不同网段. 准备: 物理机:单网卡 VMware:centos 6.8 二.配置 第一步:新建虚拟机VMware,cento ...
- 树莓派4B切换国内源-亲测有效
参考:https://blog.csdn.net/qq_30290661/article/details/103386997 修改/etc/apt/sources.list,去掉自带的源,添加如下源: ...