Python -- Use of the plotting tool matplotlib

Source: Internet
Author: User

3. click the button to draw a sine wave.


[Python]
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
 
Def draw_sin ():
# Draw a circle of sin
T = np. arange (1,256, 1)
Y = np. sin (2 * np. pi * t/256)
Plt. plot (t, y, 'G ')
Plt. show ()
 
Root = Tk (className = 'drawsin ')
Label = Label (root)
Label ['text'] = 'draw sin'
Label. pack ()
Button = Button (root)
Button ['text'] = 'draw'
Button ['command'] = draw_sin
Button. pack ()
Root. mainloop ()

From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np

Def draw_sin ():
# Draw a circle of sin
T = np. arange (1,256, 1)
Y = np. sin (2 * np. pi * t/256)
Plt. plot (t, y, 'G ')
Plt. show ()

Root = Tk (className = 'drawsin ')
Label = Label (root)
Label ['text'] = 'draw sin'
Label. pack ()
Button = Button (root)
Button ['text'] = 'draw'
Button ['command'] = draw_sin
Button. pack ()
Root. mainloop ()
Effect

Show Main Menu

 
 


Click the button to draw a picture

 
 


4. click the button to change the waveform.


[Python]
#! Usr/bin/env/python
# Coding = UTF-8
 
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Import sys
 
# Number of point
Number = 1024
# Init frequency value
Frequency = 1
# Set the recur depth
Sys. setrecursionlimit (1000000)
 
Def draw_sin ():
'''''Raw a circle of sin '''
# Generate the time base
T = np. arange (1, Number, 1)
# Generate the signal
Y = np. sin (2 * np. pi * frequency * t/Number)
Plt. plot (t, y)
Plt. grid (True)
Plt. text (900, 0.75, 'frequency is '+ str (Frequency ))
Plt. show ()
 
Def frequency_plus ():
'''''Function of add the frequency and plot the signal '''
# Notice: frequency is a global variable
Global frequency
Frequency = frequency + 1
# Clear a figure window
Plt. clf ()
Draw_sin ()
 
Def my_button (root, label_text, button_text, button_func ):
'''''Function of creat label and button '''
# Label details
Label = Label (root)
Label ['text'] = label_text
Label. pack ()
# Label details
Button = Button (root)
Button ['text'] = button_text
Button ['command'] = button_func
Button. pack ()

Def main ():
'''''Main function '''
Root = Tk (className = 'drawsin ')
# Draw button function
My_button (root, 'draw sin', 'click to draw', draw_sin)
# Frequency plus function
My_button (root, 'freq Plus ', 'click to Plus', frequency_plus)
Root. mainloop ()

If _ name _ = "_ main __":
Main ()

#! Usr/bin/env/python
# Coding = UTF-8

From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Import sys

# Number of point
Number = 1024
# Init frequency value
Frequency = 1
# Set the recur depth
Sys. setrecursionlimit (1000000)

Def draw_sin ():
'''Raw a circle of sin '''
# Generate the time base
T = np. arange (1, Number, 1)
# Generate the signal
Y = np. sin (2 * np. pi * frequency * t/Number)
Plt. plot (t, y)
Plt. grid (True)
Plt. text (900, 0.75, 'frequency is '+ str (Frequency ))
Plt. show ()

Def frequency_plus ():
'''Function of add the frequency and plot the signal '''
# Notice: frequency is a global variable
Global frequency
Frequency = frequency + 1
# Clear a figure window
Plt. clf ()
Draw_sin ()

Def my_button (root, label_text, button_text, button_func ):
'''Function of creat label and button '''
# Label details
Label = Label (root)
Label ['text'] = label_text
Label. pack ()
# Label details
Button = Button (root)
Button ['text'] = button_text
Button ['command'] = button_func
Button. pack ()
 
Def main ():
'''Main function '''
Root = Tk (className = 'drawsin ')
# Draw button function
My_button (root, 'draw sin', 'click to draw', draw_sin)
# Frequency plus function
My_button (root, 'freq Plus ', 'click to Plus', frequency_plus)
Root. mainloop ()
 
If _ name _ = "_ main __":
Main ()
Effect

Show Main Menu

 
 


Click the button to change the frequency

 
 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.