This repository was archived by the owner on Jun 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (55 loc) · 2.13 KB
/
Copy pathmain.py
File metadata and controls
69 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import io
import flet as ft
# from os.path import dirname, join
def main(page: ft.Page):
page.title = "Flet libs test"
def matplotlib_tests(e):
def test_basic():
try:
import matplotlib
page.add(ft.Text("import matplotlib: OK"))
from flet.matplotlib_chart import MatplotlibChart
import matplotlib.pyplot as plt
matplotlib.use("svg")
fig, ax = plt.subplots()
fruits = ["apple", "blueberry", "cherry", "orange"]
counts = [40, 100, 30, 55]
bar_labels = ["red", "blue", "_red", "orange"]
bar_colors = ["tab:red", "tab:blue", "tab:red", "tab:orange"]
ax.bar(fruits, counts, label=bar_labels, color=bar_colors)
ax.set_ylabel("fruit supply")
ax.set_title("Fruit supply by kind and color")
ax.legend(title="Fruit color")
page.add(MatplotlibChart(fig, expand=True))
plt.figure()
plt.plot([1, 2])
bio = io.BytesIO()
plt.savefig(bio, format="png")
b = bio.getvalue()
EXPECTED_LEN = 16782
assert len(b) > int(EXPECTED_LEN * 0.8)
assert len(b) < int(EXPECTED_LEN * 1.2)
assert b[:24] == (
b"\x89PNG\r\n\x1a\n"
+ b"\x00\x00\x00\rIHDR" # File header
+ b"\x00\x00\x02\x80" # Header chunk header
+ b"\x00\x00\x01\xe0" # Width 640 # Height 480
)
page.add(ft.Text("matplotlib: test_basic - OK"))
except Exception as e:
page.add(
ft.Text(f"matplotlib: test_basic - error: {e}", selectable=True)
)
test_basic()
page.add(
ft.SafeArea(
ft.Column(
[
ft.ElevatedButton(
"Run Matplotlib tests", on_click=matplotlib_tests
),
]
)
)
)
ft.app(main)