Skip to content

Commit 87d804b

Browse files
committed
adding scatter plots, packing library
1 parent 18f491b commit 87d804b

File tree

9 files changed

+102
-9
lines changed

9 files changed

+102
-9
lines changed

circuitpython_uplot/__init__.py

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

circuitpython_uplot/scatter.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2023 Jose D. Montoya
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
6+
"""
7+
8+
`scatter`
9+
================================================================================
10+
11+
CircuitPython scatter graph
12+
13+
* Author(s): Jose D. Montoya
14+
15+
16+
"""
17+
from ulab import numpy as np
18+
import displayio
19+
from vectorio import Circle
20+
21+
# pylint: disable=too-few-public-methods, invalid-name
22+
class scatter:
23+
"""
24+
Main class to display different graphics
25+
"""
26+
27+
def __init__(self, plot, x, y, radius=3):
28+
"""
29+
30+
:param plot: Plot Object for the scatter to be drawn
31+
:param x: x points coordinates
32+
:param y: y points coordinates
33+
:param radius: circle radius
34+
35+
"""
36+
plot._drawbox()
37+
38+
x = np.array(x)
39+
y = np.array(y)
40+
41+
xnorm = np.array(
42+
plot.normalize(np.min(x), np.max(x), plot._newxmin, plot._newxmax, x),
43+
dtype=np.uint16,
44+
)
45+
ynorm = np.array(
46+
plot.normalize(np.min(y), np.max(y), plot._newymin, plot._newymax, y),
47+
dtype=np.uint16,
48+
)
49+
50+
palette = displayio.Palette(1)
51+
palette[0] = 0xFFFFFF
52+
for i, _ in enumerate(x):
53+
plot.append(
54+
Circle(pixel_shader=palette, radius=radius, x=xnorm[i], y=ynorm[i])
55+
)

uplot.py renamed to circuitpython_uplot/uplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from vectorio import Circle
2727
from ulab import numpy as np
2828

29+
2930
__version__ = "0.0.0+auto.0"
3031
__repo__ = "https://github.com/adafruit/CircuitPython_uplot.git"
3132

@@ -74,15 +75,15 @@ def __init__(self, x=0, y=0, width=None, height=None, padding=15):
7475

7576
def axs_params(self, axstype="box"):
7677
"""
77-
:param axs:
78+
Setting up axs visibility
79+
80+
:param axs: argument with the kind of axs you selected
7881
:return: none
7982
8083
"""
81-
print("aca", axstype)
8284
self._axesparams = axstype
8385

8486
def _drawbox(self):
85-
print(self._axesparams)
8687
if self._axesparams == "cartesian":
8788
draw_box = [True, True, False, False]
8889
elif self._axesparams == "line":

docs/api.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
55
.. use this format as the module name: "adafruit_foo.foo"
66
7-
.. automodule:: uplot
7+
.. automodule:: circuitpython_uplot.uplot
8+
:members:
9+
10+
.. automodule:: circuitpython_uplot.scatter
811
:members:

examples/uplot_integration_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import board
66
from ulab import numpy as np
77
from uhistogram import Histogram
8-
from uplot import Uplot
9-
8+
from circuitpython_uplot.uplot import Uplot
109

1110
# Setting Up the histogram
1211
data = [5, 4, 3, 2, 7, 5, 3, 3, 3, 3, 2, 9, 7, 6]

examples/uplot_plot_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import board
77
from ulab import numpy as np
8-
from uplot import Uplot
8+
from circuitpython_uplot.uplot import Uplot
99

1010
display = board.DISPLAY
1111
plot = Uplot(0, 0, display.width, display.height)

examples/uplot_scatter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import time
6+
from random import choice
7+
import board
8+
from ulab import numpy as np
9+
from circuitpython_uplot.uplot import Uplot
10+
from circuitpython_uplot.scatter import scatter
11+
12+
13+
# Setting up the display
14+
display = board.DISPLAY
15+
16+
plot = Uplot(0, 0, display.width, display.height)
17+
18+
# Setting up tick parameters
19+
plot.tick_params(tickheight=12, tickcolor=0xFF0008, tickgrid=True)
20+
plot.axs_params(axstype="cartesian")
21+
a = np.linspace(1, 100)
22+
b = [choice(a) for _ in a]
23+
scatter(plot, a, b)
24+
25+
# Seeting some date to plot
26+
27+
# Plotting and showing the plot
28+
display.show(plot)
29+
30+
# Adding some wait time
31+
while True:
32+
time.sleep(1)

examples/uplot_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import board
77
import displayio
8-
from uplot import Uplot
8+
from circuitpython_uplot.uplot import Uplot
99

1010
display = board.DISPLAY
1111
plot = Uplot(0, 0, display.width, display.height)

examples/uplot_tickparameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import board
77
from ulab import numpy as np
8-
from uplot import Uplot
8+
from circuitpython_uplot.uplot import Uplot
99

1010
# Setting up the display
1111
display = board.DISPLAY

0 commit comments

Comments
 (0)