Skip to content

Commit c60d27f

Browse files
committed
adding pictures and integration example
1 parent 4dd092f commit c60d27f

13 files changed

+130
-17
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ Introduction
1515
:target: https://github.com/psf/black
1616
:alt: Code Style: Black
1717

18-
framework to display different plots in displayio. similar to widget
18+
Framework to display different plots in displayio. Similar to widget
19+
Take a look in the examples section in RTD to see the gallery.
20+
21+
.. image:: https://github.com/jposada202020/CircuitPython_uplot/blob/main/docs/uplot_ex4.jpg
1922

2023

2124
Dependencies
@@ -32,9 +35,6 @@ or individual libraries can be installed using
3235

3336
=====================
3437

35-
.. note:: This library is not available on PyPI yet. Install documentation is included
36-
as a standard element. Stay tuned for PyPI availability!
37-
3838
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3939
PyPI <https://pypi.org/project/circuitpython-uplot/>`_.
4040
To install for current user:

docs/examples.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Ensure your device works with this simple test.
77
:caption: examples/uplot_simpletest.py
88
:linenos:
99

10+
.. image:: ../docs/uplot_ex1.jpg
11+
1012
Plot Example
1113
-------------
1214

@@ -16,11 +18,25 @@ Pot some data for x and y
1618
:caption: examples/uplot_plot_example.py
1719
:linenos:
1820

21+
.. image:: ../docs/uplot_ex4.jpg
22+
1923
Tick Parameters Settings Example
2024
----------------------------------
2125

22-
Settting up the ticks parameters
26+
Setting up the ticks parameters
2327

2428
.. literalinclude:: ../examples/uplot_tickparameters.py
2529
:caption: examples/uplot_tickparameters.py
2630
:linenos:
31+
32+
.. image:: ../docs/uplot_ex3.jpg
33+
34+
Integration Example
35+
-------------------
36+
37+
Example showing different graphcals elements integration
38+
39+
.. literalinclude:: ../examples/uplot_integration_example.py
40+
:caption: examples/uplot_integration_example.py
41+
:linenos:
42+
.. image:: ../docs/uplot_ex5.jpg

docs/uplot_ex1.jpg

6.5 KB
Loading

docs/uplot_ex1.jpg.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2023 Jose David M.
2+
3+
SPDX-License-Identifier: MIT

docs/uplot_ex3.jpg

22.4 KB
Loading

docs/uplot_ex3.jpg.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2023 Jose David M.
2+
3+
SPDX-License-Identifier: MIT

docs/uplot_ex4.jpg

10.6 KB
Loading

docs/uplot_ex4.jpg.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2023 Jose David M.
2+
3+
SPDX-License-Identifier: MIT

docs/uplot_ex5.jpg

11.8 KB
Loading

docs/uplot_ex5.jpg.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2023 Jose David M.
2+
3+
SPDX-License-Identifier: MIT

examples/uplot_integration_example.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import board
6+
from ulab import numpy as np
7+
from uhistogram import Histogram
8+
from uplot import Uplot
9+
10+
11+
# Setting Up the histogram
12+
data = [5, 4, 3, 2, 7, 5, 3, 3, 3, 3, 2, 9, 7, 6]
13+
my_box = Histogram(data, x=50, y=50, width=100, height=100)
14+
my_box.draw()
15+
16+
# Setting up the display
17+
display = board.DISPLAY
18+
19+
# Adding the plot area
20+
plot = Uplot(0, 0, display.width, display.height)
21+
22+
# Seeting some date to plot
23+
x = np.linspace(-4, 4, num=50)
24+
constant = 1.0 / np.sqrt(2 * np.pi)
25+
y = constant * np.exp((-(x**2)) / 2.0)
26+
27+
# Plotting and showing the plot
28+
plot.draw_plot(x, y)
29+
plot.append(my_box)
30+
31+
# Adding a circle
32+
plot.draw_circle(radius=8, x=120, y=120)
33+
34+
# Showing in the screen
35+
display.show(plot)
36+
37+
while True:
38+
pass

examples/uplot_tickparameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plot = Uplot(0, 0, display.width, display.height)
1515

1616
# Setting up tick parameters
17-
plot.tick_params(tickheight=12, tickcolor=0xFF00FF)
17+
plot.tick_params(tickheight=12, tickcolor=0xFF00FF, tickgrid=True)
1818

1919
# Seeting some date to plot
2020
x = np.linspace(-4, 4, num=50)

uplot.py

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(self, x=0, y=0, width=None, height=None, padding=15):
5252
self._tickheight = 8
5353
self._tickcolor = 0xFFFFFF
5454
self._showticks = False
55+
self._tickgrid = False
5556

5657
self._width = width
5758
self._height = height
@@ -178,16 +179,12 @@ def _draw_ticks(self, x, y):
178179
179180
"""
180181
ticks = np.array([10, 30, 50, 70, 90])
181-
subticks = np.array([20, 40, 60, 80, 100])
182-
ticksxnorm = np.array(self.normalize(10, 100, np.min(x), np.max(x), ticks))
183-
ticksynorm = np.array(self.normalize(10, 100, np.min(y), np.max(y), ticks))
182+
subticks = np.array([20, 40, 60, 80])
183+
ticksxnorm = np.array(self.normalize(0, 100, np.min(x), np.max(x), ticks))
184+
ticksynorm = np.array(self.normalize(0, 100, np.min(y), np.max(y), ticks))
184185

185-
subticksxnorm = np.array(
186-
self.normalize(10, 100, np.min(x), np.max(x), subticks)
187-
)
188-
subticksynorm = np.array(
189-
self.normalize(10, 100, np.min(y), np.max(y), subticks)
190-
)
186+
subticksxnorm = np.array(self.normalize(0, 100, np.min(x), np.max(x), subticks))
187+
subticksynorm = np.array(self.normalize(0, 100, np.min(y), np.max(y), subticks))
191188

192189
ticksxrenorm = np.array(
193190
self.normalize(
@@ -251,16 +248,66 @@ def _draw_ticks(self, x, y):
251248
2,
252249
)
253250

254-
def tick_params(self, tickheight=8, tickcolor=0xFFFFFF):
251+
if self._tickgrid:
252+
self._draw_gridx(ticksxrenorm)
253+
self._draw_gridy(ticksyrenorm)
254+
255+
def tick_params(self, tickheight=8, tickcolor=0xFFFFFF, tickgrid=False):
255256
"""
256257
Function to set ticks parameters
257258
258259
:param tickheight:
259260
:param tickcolor:
260-
:return:
261+
262+
:return: None
261263
262264
"""
263265

264266
self._showticks = True
265267
self._tickheight = tickheight
266268
self._plot_palette[2] = tickcolor
269+
self._tickgrid = tickgrid
270+
271+
def _draw_gridx(self, ticks_data):
272+
"""
273+
draw plot grid
274+
275+
:return: None
276+
277+
"""
278+
grid_espace = 10
279+
line_lenght = 10
280+
for tick in ticks_data:
281+
start = self._newymin
282+
while start >= self._newymax:
283+
draw_line(
284+
self._plotbitmap,
285+
tick,
286+
start,
287+
tick,
288+
start - line_lenght,
289+
2,
290+
)
291+
start = start - grid_espace - line_lenght
292+
293+
def _draw_gridy(self, ticks_data):
294+
"""
295+
draw plot grid
296+
297+
:return: None
298+
299+
"""
300+
grid_espace = 10
301+
line_lenght = 10
302+
for tick in ticks_data:
303+
start = self._newxmin
304+
while start <= self._newxmax:
305+
draw_line(
306+
self._plotbitmap,
307+
start,
308+
tick,
309+
start + line_lenght,
310+
tick,
311+
2,
312+
)
313+
start = start + grid_espace + line_lenght

0 commit comments

Comments
 (0)