Advertisement
ostapdontstop

plot-input

May 15th, 2020
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.widgets import TextBox
  4. import random
  5.  
  6. fig, ax = plt.subplots(2,2,sharey=True)
  7.  
  8. plt.subplots_adjust(bottom=0.2)
  9.  
  10.  
  11.  
  12. n = 500
  13. x = [random.random() for i in range(n)]
  14. ax[0,0].hist(x,20)
  15.  
  16.  
  17.  
  18. def submit(text):
  19.     try:
  20.         n = int(text)
  21.         if n <= 0:
  22.             raise ValueError
  23.  
  24.     except ValueError:
  25.         return
  26.  
  27.  
  28.     x = [random.random() for i in range(n)]
  29.     ax[0,0].clear()
  30.     ax[0,0].hist(x,20)
  31.     plt.draw()
  32.  
  33.  
  34. axbox = plt.axes([0.1, 0.05, 0.8, 0.075])
  35. text_box = TextBox(axbox, 'Длина', initial=str(n))
  36. text_box.on_submit(submit)
  37.  
  38. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement