当前位置:网站首页>matplotlib. Widgets are easy to use
matplotlib. Widgets are easy to use
2022-07-06 07:59:00 【The story has turned several pages】
matplotlib Official document website :https://matplotlib.org/
My idea is to learn from cases rather than looking at them one by one , Learning in cases can quickly master , And can keep learning enthusiasm , Let's start .
List of articles
1. Introduce
This module is matplotlib Medium GUI modular , Can be adjusted by bottom To change the displayed results in real time
2. structure
Don't talk much , Directly on the official documents 
3. Case study 1
The experimental environment is python3.6
Mission : Realize a small program that can change the value and image in real time
1. First , We import the required libraries
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
2. Define the main function :
if __name__ == '__main__':
fig = plt.figure() # Create an image object
ax1 = fig.add_subplot(111) # take ax1 Set to place in image , There is only one sub picture in the image
plt.subplots_adjust(bottom=0.3)# Set the distance between the image and the bottom in the last display box 40% It's about , So as to drag the display of the bar later .
s1 = plt.axes([0.25, 0.1, 0.6, 0.05], facecolor='yellow') # Set up slider1 The location of
slider1 = Slider(s1, 'gamma',valmin=0.0, valmax=100.0, valinit=10.0 ,valstep=1.0)
slider1.on_changed(update)# This code is crucial , For real-time updates
slider1.reset()#Reset the slider to the initial value.
slider1.set_val(10.0)#Set slider value to val.
plt.show()
3. then , We add update function
To achieve real-time updates, we must first establish a update Function to get the value updated in real time update Function can only have one argument , namely val,val yes validation Abbreviation , Means variable .
def update(val):
gamma = slider1.val
x = np.linspace(1,100,100)
y = np.sin(x*np.log(gamma))
plt.plot(x,y)
ax1.clear()
ax1.plot(x,y)
The complete code is as follows :
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
def update(val):
gamma = slider1.val
x = np.linspace(1,100,100)
y = np.sin(x*np.log(gamma))# Set a beautiful function casually
plt.plot(x,y)
ax1.clear()
ax1.plot(x,y)
if __name__ == '__main__':
fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.subplots_adjust(bottom=0.3)
s1 = plt.axes([0.25, 0.1, 0.6, 0.05], facecolor='yellow') # Set up slider1 The location of
slider1 = Slider(s1, 'gamma',valmin=0.0, valmax=100.0, valinit=10.0 ,valstep=1.0)# Set the properties of the slider
slider1.on_changed(update)
slider1.reset()#Reset the slider to the initial value.
slider1.set_val(10.0)#Set slider value to val.
plt.show()
After running, it first appears like this 
Try to jump the sliding shaft below , Something amazing happened 
To be continued 2022.2.12
边栏推荐
- MES, APS and ERP are essential to realize fine production
- 【T31ZL智能视频应用处理器资料】
- flask返回文件下载
- edge浏览器 路径获得
- 649. Dota2 Senate
- 在 uniapp 中使用阿里图标
- MEX有关的学习
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- [1. Delphi foundation] 1 Introduction to Delphi Programming
- opencv学习笔记八--答题卡识别
猜你喜欢

Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University

【T31ZL智能视频应用处理器资料】

Leetcode question brushing record | 203_ Remove linked list elements
![datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在](/img/17/415e66d67afb055e94a966de25c2bc.png)
datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在

好用的TCP-UDP_debug工具下载和使用

Machine learning - decision tree

Esrally domestic installation and use pit avoidance Guide - the latest in the whole network

23. Update data

Solution: intelligent site intelligent inspection scheme video monitoring system

Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
随机推荐
NFT smart contract release, blind box, public offering technology practice -- contract
C语言 - 位段
数字经济时代,如何保障安全?
The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat
opencv学习笔记九--背景建模+光流估计
Common functions for PHP to process strings
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
数据治理:微服务架构下的数据治理
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
HTTP cache, forced cache, negotiated cache
将 NFT 设置为 ENS 个人资料头像的分步指南
数据治理:元数据管理篇
Qualitative risk analysis of Oracle project management system
【T31ZL智能视频应用处理器资料】
Make learning pointer easier (3)
MFC sends left click, double click, and right click messages to list controls
esRally国内安装使用避坑指南-全网最新
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Machine learning - decision tree
Easy to use tcp-udp_ Debug tool download and use