1
0

line_plot_documentation.py 1020 B

1234567891011121314151617181920212223242526272829303132
  1. from typing import Dict
  2. from nicegui import ui
  3. def main_demo() -> None:
  4. from datetime import datetime
  5. import numpy as np
  6. line_plot = ui.line_plot(n=2, limit=20, figsize=(3, 2), update_every=5) \
  7. .with_legend(['sin', 'cos'], loc='upper center', ncol=2)
  8. def update_line_plot() -> None:
  9. now = datetime.now()
  10. x = now.timestamp()
  11. y1 = np.sin(x)
  12. y2 = np.cos(x)
  13. line_plot.push([now], [[y1], [y2]])
  14. line_updates = ui.timer(0.1, update_line_plot, active=False)
  15. line_checkbox = ui.checkbox('active').bind_value(line_updates, 'active')
  16. # END OF DEMO
  17. def handle_change(msg: Dict) -> None:
  18. def turn_off() -> None:
  19. line_checkbox.set_value(False)
  20. ui.notify('Turning off that line plot to save resources on our live demo server. 😎')
  21. line_checkbox.value = msg['args']
  22. if line_checkbox.value:
  23. ui.timer(10.0, turn_off, once=True)
  24. line_checkbox.on('update:model-value', handle_change)