plotly_documentation.py 1007 B

1234567891011121314151617181920212223242526272829303132
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. import plotly.graph_objects as go
  5. fig = go.Figure(go.Scatter(x=[1, 2, 3, 4], y=[1, 2, 3, 2.5]))
  6. fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
  7. ui.plotly(fig).classes('w-full h-40')
  8. def more() -> None:
  9. @text_demo('Plot updates', '''
  10. This demo shows how to update the plot in real time.
  11. Click the button to add a new trace to the plot.
  12. To send the new plot to the browser, make sure to explicitly call `plot.update()` or `ui.update(plot)`.
  13. ''')
  14. def plot_updates():
  15. import numpy as np
  16. import plotly.graph_objects as go
  17. fig = go.Figure()
  18. fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
  19. plot = ui.plotly(fig).classes('w-full h-40')
  20. def add_trace():
  21. fig.add_trace(go.Scatter(x=np.arange(10), y=np.random.randn(10)))
  22. plot.update()
  23. ui.button('Add trace', on_click=add_trace)