Simple test
Ensure your device works with this simple test.
examples/uhistogram_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
2#
3# SPDX-License-Identifier: Unlicense
4"""
5Simple test to display a histogram based in some data
6"""
7import displayio
8import board
9from uhistogram import Histogram
10
11display = board.DISPLAY
12
13data = [5, 4, 3, 2, 7, 5, 3, 3, 3, 3, 2, 9, 7, 6]
14my_box = Histogram(data, x=50, y=50, width=100, height=100)
15my_box.draw()
16my_box.print_data()
17my_group = displayio.Group()
18my_group.append(my_box)
19display.show(my_group)
20
21while True:
22 pass
Text Example
A more advance example to illustrate how to add text to the histogram
examples/uhistogram_text_example.py
1# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
2#
3# SPDX-License-Identifier: Unlicense
4"""
5A more advance example to illustrate how to add text to the histogram
6"""
7
8# pylint: disable=protected-access
9
10import displayio
11import board
12import terminalio
13from adafruit_display_text import bitmap_label
14from uhistogram import Histogram
15
16display = board.DISPLAY
17
18data = [5, 4, 3, 2, 7, 5, 3, 3, 3, 3, 2, 9, 7, 6]
19my_box = Histogram(data, x=50, y=50, width=100, height=100)
20my_box.draw()
21my_group = displayio.Group()
22my_group.append(my_box)
23
24for i in range(my_box._numbins):
25
26 text_area = bitmap_label.Label(terminalio.FONT, text=str(int(my_box.bin_data[i])))
27 text_area.x = (
28 50 + my_box._xstart + int(i * 1 * my_box._graphx) + my_box._graphx // 2
29 )
30 text_area.y = 160
31 my_group.append(text_area)
32
33display.show(my_group)
34while True:
35 pass