当前位置:网站首页>使用matplotlib实现GUI交互效果
使用matplotlib实现GUI交互效果
2022-06-22 04:48:00 【爱打羽毛球的小怪兽】
以下图像中主要包含以下内容:
横纵交叉坐标定位直线、选择框按钮、复选框按钮、绘制子图

以下为上图的实现代码
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import RadioButtons,Cursor,CheckButtons#导入需要的包
x=np.linspace(0.0,2.0,1000)从0到2之间平均取1000个点
y1=1.5*np.cos(2*np.pi*x)
y2=1.0*np.cos(2*np.pi*x)
y3=0.5*np.cos(2*np.pi*x)#定义函数
fig=plt.subplots(subplot_kw={'aspect':'equal'})
line1,=ax.plot(x,y1,color='red',lw=2,visible=False,label='1.5cos(2Πx)')
line2,=ax.plot(x,y2,color='green',lw=2,label='1.0cos(2Πx)')
line3,=ax.plot(x,y3,color='orange',lw=2,label='0.5cos(2Πx)')#绘制函数
lineprops=dict(color='black',lw=1)
cursor=Cursor(ax_2,useblit=True,**lineprops,ls=':')#横纵交叉定位直线的实现
axesbgcolor='cornflowerblue'
cax=plt.axes([0.05,0.7,0.18,0.15],facecolor=axesbgcolor)#设置子图的背景颜色
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)#创建复选按钮框
cax.xaxis.set_ticks([])#消除子图的刻度线
def func(label):
index=labels.index(label)
lines[index].set_visible(not lines[index].get_visible())
plt.draw()
check.on_clicked(func)#线条的显示与否按钮的设置
ax2=plt.axes([0.05,0.4,0.15,0.15],facecolor=axesbgcolor)
radio2=RadioButtons(ax2,('red','green','orange'))#创建选择按钮框
ax2.xaxis.set_ticks([])#消除子图的刻度线
def colorfunc(label):
for line in lines:
line.set_color(label)
plt.draw()
radio2.on_clicked(colorfunc)#调用实例方法,点击标签的时候就调用指定的colorfunc函数
ax3=plt.axes([0.05,0.1,0.15,0.15],facecolor=axesbgcolor)
radio3=RadioButtons(ax3,('-','--','-.',':'))
ax3.xaxis.set_ticks([])
def linestylefunc(label):
for line in lines:
line.set_linestyle(label)
plt.draw()
radio3.on_clicked(linestylefunc)
plt.tighr_layout()
plt.show()边栏推荐
- 浏览器--常用的搜索操作符大全--使用/实例
- Use echart to draw 3D pie chart, dashboard and battery diagram
- 103.简易聊天室6:使用 Socket 通信
- [从零开始学习FPGA编程-39]:进阶篇 - 语法-硬件模块的单元测试:仿真激励、testbench
- LeetCode 437. Path sum III - binary tree series question 13
- mysql常用sql
- 网页设计与制作期末大作业报告——大学生线上花店
- 【故障诊断】stitch.py脚本失效
- QML control types: swipeview, pageindicator
- Accurate identification of bank card information - smart and fast card binding
猜你喜欢

使用Echart绘制3D饼环图、仪表盘、电池图

Introduction to AWS elastic Beanstalk

Ora-15063: ASM discovered an insufficient number of disks for diskgroup

Digital economy Wang Ning teaches you how to correctly choose short-term investment

Why does golang not recommend this/self/me/that/_ this

Postman document parameterization

Network Interview eight part essay of daily knowledge points (TCP, startling group phenomenon, collaborative process)

Disturbed when programmers are programming? Daily anecdotes

Golang為什麼不推薦使用this/self/me/that/_this

Systematic arrangement | how many children's shoes have forgotten to be done carefully before the model development (practical operation)
随机推荐
Cloud function realizes fuzzy search function
Daily question: the difference between ArrayList and LinkedList
Large website technology architecture | application server security defense
ln n, n^k , a^n, n!, n^n的极限问题
IDS interview questions collection data structure + penetration avalanche + persistence + memory elimination strategy + database double write + Sentinel
招贤纳士-第23期
Mongo Fuzzy query, with Special Characters need to escape, to Query
exness:欧洲央行行长拉加德重申计划在7月会议上加息
爬梯子&&卖卖股份的最佳时期(跑路人笔记)
Overrides vs overloads of methods
[details] domestic website filing process and steps
103. simple chat room 6: using socket communication
Windows10 cannot access LAN shared folder
Requests cookie update value
当程序员编程时被打扰 | 每日趣闻
软考2022年下半年考试科目安排
Zhongmin online: sharing online channel resources with "points" as the link
Web design and production final assignment report -- animator Hayao Miyazaki
商汤智慧医疗团队研究员解读智慧医疗下的器官图像处理
Is the Guoyuan futures account reliable? How can a novice safely open an account?