Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit bca2928

Browse files
committed
fixing_docs and adding save screenshot
1 parent 09b54c7 commit bca2928

File tree

12 files changed

+129
-22
lines changed

12 files changed

+129
-22
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unsafe-load-any-extension=no
1414

1515
[MESSAGES CONTROL]
1616
confidence=
17-
disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding,protected-access,consider-using-generator
17+
disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding,protected-access,consider-using-generator,too-few-public-methods
1818
enable=
1919

2020
[REPORTS]

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Introduction
66
:target: https://micropython-uplot.readthedocs.io/en/latest/
77
:alt: Documentation Status
88

9-
109
.. image:: https://img.shields.io/badge/micropython-Ok-purple.svg
1110
:target: https://micropython.org
1211
:alt: micropython
@@ -23,7 +22,11 @@ Introduction
2322
:target: https://github.com/psf/black
2423
:alt: Code Style: Black
2524

26-
MicroPython Graphics Library
25+
MicroPython Graphics Library. This is adapted to use Peter Hinch display driver.
26+
However Colors will be needed to be adapted. This library uses an WaveShare 3.5 display
27+
IL9486
28+
29+
.. image:: https://github.com/jposada202020/CircuitPython_uplot/blob/main/docs/readme1.png
2730

2831

2932
Installing with mip

docs/api.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ MicroPython UPLOT Library
55
.. automodule:: micropython_uplot
66
:members:
77

8-
.. automodule:: micropython_uplot.uplot
8+
.. automodule:: micropython_uplot.plot
9+
:members:
10+
11+
.. automodule:: micropython_uplot.scatter
912
:members:

docs/examples.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ Simple test
33

44
Ensure your device works with this simple test.
55

6-
.. literalinclude:: ../examples/uplot_simpletest.py
7-
:caption: examples/uplot_simpletest.py
6+
.. literalinclude:: ../examples/plot_simpletest.py
7+
:caption: examples/plot_simpletest.py
8+
:lines: 5-
9+
10+
Scatter Simple Test
11+
---------------------
12+
13+
Scatter simple test
14+
15+
.. literalinclude:: ../examples/scatter_example.py
16+
:caption: examples/scatter_example.py
17+
:lines: 5-
18+
19+
Scatter Variable Radius
20+
------------------------
21+
22+
Scatter example using different Radii for each data point
23+
24+
.. literalinclude:: ../examples/scatter_circle_variable_radius.py
25+
:caption: examples/scatter_example.py
26+
:lines: 5-
27+
28+
Scatter Different Datasets
29+
----------------------------
30+
31+
Scatter example using different datasets
32+
33+
.. literalinclude:: ../examples/scatter_different_datasets.py
34+
:caption: examples/scatter_different_datasets.py
835
:lines: 5-

docs/readme1.png

5.2 KB
Loading

examples/plot_simpletest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727

2828

2929
display.show()
30+
31+
# my_plot.savingppm()

examples/scatter_different_datasets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
)
3030

3131

32-
a = list(linspace(4, 200, 50))
33-
z = [4, 5, 6, 7, 8]
32+
a = list(linspace(10, 200, 50))
33+
z = [2, 3, 4, 5, 6]
3434
radi = [choice(z) for _ in a]
3535
b = [choice(a) for _ in a]
3636
Scatter(
@@ -73,3 +73,4 @@
7373
)
7474

7575
display.show()
76+
plot.savingppm("newfile.ppm")

micropython_uplot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
`uplot`
2+
`plot`
33
================================================================================
44
55
* Author(s): Jose D. Montoya

micropython_uplot/plot.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class PLOT:
4343
Defaults to white ''(255, 255, 255)``
4444
:param int tickx_height: x axes tick height in pixels. Defaults to 8.
4545
:param int ticky_height: y axes tick height in pixels. Defaults to 8.
46-
:param int scale: scale of the plot. Defaults to 1.
4746
4847
"""
4948

@@ -65,8 +64,12 @@ def __init__(
6564
self._background_color = set_color(
6665
display, 0, background_color[0], background_color[1], background_color[2]
6766
)
67+
6868
self._tickcolor = set_color(display, 1, 255, 255, 255)
6969
self._boxcolor = set_color(display, 2, box_color[0], box_color[1], box_color[2])
70+
self._color0 = background_color
71+
self._color1 = box_color
72+
self._color2 = (255, 255, 255)
7073

7174
self._axesparams = "box"
7275
self._decimal_points = None
@@ -366,6 +369,7 @@ def tick_params(
366369
self._tickcolor = set_color(
367370
self._display, 1, tickcolor[0], tickcolor[1], tickcolor[2]
368371
)
372+
self._color2 = tickcolor
369373

370374
self._tickgrid = tickgrid
371375
self._showtext = showtext
@@ -395,7 +399,7 @@ def show_text(
395399
distance = 5
396400

397401
if ax == "y":
398-
x = x - font_width - distance
402+
x = x - font_width * (len(text)) - distance
399403
y = y - font_height // 2
400404
if ax == "x":
401405
x = x - font_width // 2
@@ -449,16 +453,64 @@ def _draw_gridx(self, ticks_data: list[int]) -> None:
449453
)
450454
start = start - self._grid_espace - self._grid_lenght
451455

452-
def writeplainpbm(self, file):
456+
def _writeplainpbm(self, file: str = "newfile.pbm"):
453457
"""
454458
Function to write a plain pbm file
459+
adapted from https://github.com/orgs/micropython/discussions/10785
460+
Author: Stewart Russell
455461
"""
456462
with open(file, "wb") as file_write:
457463
file_write.write("P1" + "\n")
458464
file_write.write(str(480) + " " + str(320) + "\n")
459465
for y in range(320):
460466
for x in range(480):
461-
print(str(self._display.pixel(x, y)))
462467
file_write.write(str(self._display.pixel(x, y)))
463468
file_write.write("\n")
464469
file_write.close()
470+
471+
def _savingppm(self, filename: str = "picture.ppm", width=480, height=320):
472+
"""
473+
Function to save the screen as a ppm file
474+
Adapted from https://gist.github.com/nicholasRutherford/c95a55239e03ba99bab3
475+
Author: Nicholas Rutherford
476+
477+
:param str filename: picture filename
478+
:param int width: screenshot width in pixels
479+
:param int height: screenshot height in pixels
480+
481+
This function requires adding the colors used manually in the z list
482+
"""
483+
484+
z = [
485+
self._color0,
486+
self._color2,
487+
self._color1,
488+
(255, 255, 0),
489+
(255, 69, 69),
490+
(34, 98, 129),
491+
]
492+
493+
# Header values for the file
494+
comment = b"MicroPlot"
495+
ftype = b"P6"
496+
497+
# First write the header values
498+
with open(filename, "wb+") as ppmfile:
499+
ppmfile.write(b"%s\n" % (ftype))
500+
ppmfile.write(b"#%s\n" % comment)
501+
ppmfile.write(b"%d %d\n" % (width, height))
502+
ppmfile.write(b"255\n")
503+
504+
for y in range(height):
505+
for x in range(width):
506+
if self._display.pixel(x, y) > 5:
507+
print(self._display.pixel(x, y))
508+
ppmfile.write(
509+
b"%c%c%c"
510+
% (
511+
z[self._display.pixel(x, y)][0],
512+
z[self._display.pixel(x, y)][1],
513+
z[self._display.pixel(x, y)][2],
514+
)
515+
)
516+
ppmfile.close()

micropython_uplot/scatter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
1313
1414
"""
15-
16-
from micropython_uplot.colors import set_color
1715
from array import array
16+
from micropython_uplot.colors import set_color
1817

1918
try:
2019
from typing import Union, Optional
21-
from typing_extensions import Literal
2220
from micropython_uplot.plot import PLOT
2321
except ImportError:
2422
pass

0 commit comments

Comments
 (0)