首页 技术 正文
技术 2022年11月19日
0 收藏 757 点赞 2,832 浏览 2240 个字

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 Cursorlineprops = 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 CheckButtonsx = 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开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850