plotly_chart.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from flet_core import Column, MainAxisAlignment, Row
  2. from flet.plotly_chart import PlotlyChart
  3. import plotly
  4. import plotly.express
  5. # import matplotlib
  6. # import matplotlib.pyplot as plt
  7. from flet.matplotlib_chart import MatplotlibChart
  8. # matplotlib.use("svg")
  9. class ChartPage():
  10. '''chart page '''
  11. def draw_chart(self):
  12. ''' draw chart '''
  13. x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
  14. 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
  15. fig = plotly.graph_objects.Figure()
  16. # 箱线图
  17. fig.add_trace(plotly.graph_objects.Box(
  18. y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
  19. x=x,
  20. name='kale',
  21. marker_color='#3D9970'
  22. ))
  23. fig.add_trace(plotly.graph_objects.Box(
  24. y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
  25. x=x,
  26. name='radishes',
  27. marker_color='#FF4136'
  28. ))
  29. fig.add_trace(plotly.graph_objects.Box(
  30. y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],
  31. x=x,
  32. name='carrots',
  33. marker_color='#FF851B'
  34. ))
  35. fig.update_layout(
  36. yaxis_title='normalized moisture',
  37. boxmode='group' # group together boxes of the different traces for each value of x
  38. )
  39. return fig
  40. def __init__(self):
  41. ''''''
  42. super().__init__()