Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.widgets import Slider
  4. import tkinter as tk
  5.  
  6. def b1():
  7.   plt.clf()
  8.   plt.pause(0.01)
  9.   ax = fig.add_subplot(111)
  10.   x = np.arange(0, 10, 0.1)
  11.   y = np.sin(x)
  12.   ax.plot(x, y)
  13.   fig.canvas.draw_idle()
  14.  
  15. def b2():
  16.   plt.clf()
  17.   plt.pause(0.01)
  18.   ax1 = fig.add_subplot(211)
  19.   ax2 = fig.add_subplot(212)
  20.   x = np.arange(0, 20, 0.1)
  21.   y = np.sin(x**2)
  22.   y2 = np.sin(np.sqrt(x))*2
  23.   ax1.plot(x, y)
  24.   ax2.plot(x, y2)
  25.   fig.canvas.draw_idle()
  26.  
  27. rt = tk.Tk()
  28. btn1 = tk.Button(rt, text='1', command=b1)
  29. btn2 = tk.Button(rt, text='2', command=b2)
  30. btn1.grid(column=0, row=0)
  31. btn2.grid(column=1, row=0)
  32. fig = plt.figure(figsize=(8, 4))
  33. rt.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement