Simple test

Ensure your device works with this simple test.

examples/plot_simpletest.py
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT


# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)


my_plot = PLOT(display, 50, 50, 200, 200, padding=25, box_color=(0, 0, 255))
my_plot.axs_params(axstype="box")

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220]
my_plot.tick_params(show_ticks=True, tickgrid=True, showtext=True)
my_plot._draw_ticks(x, y)


display.show()
_images/plot.jpg

Cartesian Simple Test

Cartesian Simple Test

examples/cartesian_simpletest.py
import gc
import math
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.cartesian import Cartesian

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 300, 250, padding=1, box_color=(255, 255, 255))
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)

# Creating some points to graph
x = list(linspace(-4, 4, 25))
constant = 1.0 / math.sqrt(2 * math.pi)
y = [constant * math.exp((-(_**2)) / 2.0) for _ in x]
# Drawing the graph
Cartesian(plot, x, y, line_color=(255, 255, 0))

display.show()
_images/cartesian_simpletest.jpg

Cartesian Line Types

Cartesian Line Types examples

examples/cartesian_linetypes.py
import gc
import math
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.cartesian import Cartesian

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 300, 250, padding=1, box_color=(255, 255, 255))
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)

# Creating some points to graph
x = list(linspace(-4, 4, 50))
constant = 1.0 / math.sqrt(2 * math.pi)
y = [constant * math.exp((-(_**2)) / 2.0) for _ in x]
y2 = [constant / 2 * math.exp((-(_**2)) / 1.0) for _ in x]
y3 = [10 + (2 + constant / 1.1 * math.exp((-(_**2)) / 0.5 + 2)) for _ in x]
# Drawing the graph
Cartesian(plot, x, y, line_color=(255, 255, 0), line_style=".")
Cartesian(plot, x, y2, line_color=(0, 255, 0), line_style="-.-")
p = Cartesian(plot, x, y3, line_color=(0, 255, 255), line_style="- -")
display.show()
_images/line_types.jpg

Cartesian Fill

Cartesian Curve fill

examples/cartesian_fill.py
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.cartesian import Cartesian

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 460, 150, padding=1, box_color=(255, 255, 255))
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)

# Creating some points to graph
x = list(linspace(0, 4, 25))
y = [value * (value - 2) ** 2 for value in x]

# Drawing the graph
Cartesian(plot, x, y, rangey=[-1, 18], line_color=(255, 89, 0), fill=True)

display.show()
_images/cartesian_fill.jpg

Cartesian Trig functions

Cartesian Trigonometric functions example

examples/cartesian_trig_functions.py
from math import pi, sin, cos
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.cartesian import Cartesian

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 460, 300, padding=1, box_color=(255, 255, 255))
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=False
)

# Compute the x and y coordinates for points on a sine curve
x = list(linspace(0, 3 * pi, 45))
y = [sin(value) for value in x]
y2 = [cos(value) for value in x]

# Drawing the graph
Cartesian(plot, x, y, rangex=[0, 10], rangey=[-1.1, 1.2])
Cartesian(plot, x, y2, rangex=[0, 10], rangey=[-1.1, 1.2], line_color=(255, 0, 0))
display.text("sin(x)", 100, 30, 3)
display.text("cos(x)", 50, 230, 4)

display.show()
_images/cartesian_trig.jpg

Scatter Simple Test

Scatter simple test

examples/scatter_example.py
import gc
from random import choice
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.colors import create_color
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.scatter import Scatter

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

GREEN = create_color(display, 1, 0, 255, 0)
BLACK = create_color(display, 2, 0, 0, 0)

plot = PLOT(display, 50, 50, 200, 200, padding=1, box_color=(0, 0, 255))
plot.axs_params(axstype="box")
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)

a = list(linspace(1, 100, 100))
b = [choice(a) for _ in a]
Scatter(plot, a, b, pointer="diamond")

display.show()
_images/scatter_example.jpg

Scatter Variable Radius

Scatter example using different Radii for each data point

examples/scatter_example.py
import gc
from random import choice
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.colors import create_color
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.scatter import Scatter

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

GREEN = create_color(display, 1, 0, 255, 0)
BLACK = create_color(display, 2, 0, 0, 0)

plot = PLOT(display, 50, 50, 200, 200, padding=1, box_color=(0, 0, 255))
plot.axs_params(axstype="box")
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)

a = list(linspace(1, 200, 80))
z = [2, 3, 5, 6]
radi = [choice(z) for _ in a]
b = [choice(a) for _ in a]

Scatter(
    plot,
    a,
    b,
    rangex=[0, 210],
    rangey=[0, 210],
    radius=radi,
    pointer_color=(89, 10, 128),
)

display.show()
_images/scatter_radius.jpg

Scatter Different Datasets

Scatter example using different datasets

examples/scatter_different_datasets.py
import gc
from random import choice
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.scatter import Scatter, Pointer

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 50, 50, 200, 200, padding=1, box_color=(0, 0, 255))
plot.axs_params(axstype="box")
plot.tick_params(
    tickx_height=12, ticky_height=12, tickcolor=(100, 100, 100), tickgrid=True
)


a = list(linspace(10, 200, 50))
z = [2, 3, 4, 5, 6]
radi = [choice(z) for _ in a]
b = [choice(a) for _ in a]
Scatter(
    plot,
    a,
    b,
    rangex=[0, 210],
    rangey=[0, 210],
    radius=radi,
    pointer_color=(255, 255, 0),
)
a = list(linspace(50, 170, 50))
radi = [choice(z) for _ in a]
b = [choice(a) for _ in a]
Scatter(
    plot,
    a,
    b,
    rangex=[0, 210],
    rangey=[0, 210],
    radius=radi,
    pointer_color=(255, 69, 69),
)
a = list(linspace(50, 100, 25))
z = [
    4,
    5,
    6,
]
radi = [choice(z) for _ in a]
b = [int(choice(a) / 1.2) for _ in a]
Scatter(
    plot,
    a,
    b,
    rangex=[0, 210],
    rangey=[0, 210],
    pointer=Pointer.TRIANGLE,
    pointer_color=(34, 98, 129),
)

display.show()
_images/scatter_datasets.jpg

Scatter Different Pointers

Scatter example using different Pointers

examples/scatter_pointers.py
import gc
from random import choice
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.scatter import Scatter, Pointer

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 0, 0, display.width // 2, display.height // 2, padding=1)
plot2 = PLOT(display, 240, 0, display.width // 2, display.height // 2, padding=1)
plot3 = PLOT(display, 0, 160, display.width // 2, display.height // 2, padding=1)
plot4 = PLOT(display, 240, 160, display.width // 2, display.height // 2, padding=1)

# Creating some Data
a = list(linspace(1, 100, 100))
b = [choice(a) for _ in a]
Scatter(plot, a, b, pointer_index=4)
Scatter(
    plot2, a, b, pointer=Pointer.TRIANGLE, pointer_color=(255, 255, 94), pointer_index=5
)
Scatter(
    plot3, a, b, pointer=Pointer.SQUARE, pointer_color=(255, 255, 255), pointer_index=6
)
Scatter(
    plot4, a, b, pointer=Pointer.DIAMOND, pointer_color=(255, 50, 255), pointer_index=7
)

display.show()
_images/scatter_pointers.jpg

Bar Simple Test

Bar Simple Test

examples/bar_simpletest.py
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.bar import Bar


# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)


my_plot = PLOT(display, 10, 10, 250, 250, padding=1, box_color=(255, 255, 255))
my_plot.axs_params(axstype="box")

# Setting up tick parameters
a = ["a", "b", "c", "d"]
b = [3, 5, 1, 7]
colors = [
    (255, 0, 0),
    (0, 255, 0),
    (0, 0, 255),
    (255, 255, 0),
]


Bar(my_plot, a, b, (255, 255, 255), True, bar_space=20, xstart=8)
# Uncomment the following line to use customize colors
# Bar(my_plot, a, b, (255, 255, 255), True, bar_space=16, xstart=5, color_palette=colors)

# Plotting and showing the plot
display.show()
my_plot._savingppm("bar.ppm")
_images/bar.jpg

Logging Simple Test

Logging Simple Test

examples/logging_simpletest.py
import gc
import math
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.logging import Logging

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 300, 250, padding=1, box_color=(255, 255, 255))

x = list(linspace(-4, 4, 25))
constant = 1.0 / math.sqrt(2 * math.pi)
y = [constant * math.exp((-(_**2)) / 2.0) for _ in x]
# Drawing the graph
my_log = Logging(plot, x, y, rangex=[-4, 4], rangey=[0, 1], line_color=(255, 255, 0))

display.show()
_images/logging_simpletest.jpg

Logging Animation

Logging Animation

examples/logging_animation.py
import time
import random
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.logging import Logging

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

my_plot = PLOT(display, 5, 5, 300, 250, padding=25, box_color=(255, 255, 255))
my_plot.tick_params(
    tickx_height=4,
    ticky_height=4,
    show_ticks=True,
    tickcolor=(255, 125, 125),
    showtext=True,
)

# Creating the x and y data
x = [
    10,
    20,
    30,
    40,
    50,
    60,
    70,
    80,
    90,
    100,
    110,
    120,
    130,
    140,
    150,
    160,
    170,
    180,
    190,
]
y = [26, 22, 24, 30, 28, 35, 26, 25, 24, 23, 20, 27, 26, 33, 24, 23, 19, 27, 26]

# Creating the random numbers
random_numbers = [19, 22, 35, 33, 24, 26, 28, 37]


dist = 1

# Creating the loggraph
my_loggraph = Logging(
    my_plot,
    x[0:dist],
    y[0:dist],
    rangex=[0, 210],
    rangey=[0, 110],
    line_color=(0, 255, 0),
    ticksx=[25, 50, 75, 100, 125, 150, 175, 200],
    ticksy=[25, 50, 75, 100],
)

display.show()

# Showing the loggraph
for _ in range(20):
    if dist > len(x):
        y.pop(0)
        y.append(random.choice(random_numbers))

    my_loggraph.draw_points(my_plot, x[0:dist], y[0:dist])
    display.show()
    dist += 1
    time.sleep(0.5)
_images/logging_animation.jpg

Map Simpletest

Map Simpletest

examples/map_simpletest.py
import gc
from math import pi, exp, sqrt
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.map import Map

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 300, 250, padding=1, box_color=(255, 255, 255))

# Setting some date to plot
x = linspace(-4, 4, 100)
y = tuple([(2.0 / sqrt(2 * pi) * exp((-(value**2)) / 4.0)) for value in x])
ymax = max(y)

y1 = []

rows, cols = (10, 10)
indice = 0

for i in range(rows):
    col = []
    for j in range(cols):
        col.append(y[indice])
        indice += 1
    y1.append(col)


# Plotting and showing the plot
Map(plot, y1, ymax, [rows, cols], (255, 0, 68), (68, 0, 255))
# Plotting and showing the plot
display.show()
_images/map_simpletest.jpg

Fillbetween Simpletest

Fillbetween Simpletest

examples/fillbetween_simpletest.py
import gc
from machine import Pin, SPI
from ili9486 import ILI9486
from micropython_uplot.plot import PLOT
from micropython_uplot.utils import linspace
from micropython_uplot.fillbetween import Fillbetween

# Pin definition
pdc = Pin(8, Pin.OUT, value=0)
prst = Pin(15, Pin.OUT, value=1)
pcs = Pin(9, Pin.OUT, value=1)
spi = SPI(1, sck=Pin(10), mosi=Pin(11), miso=Pin(12), baudrate=30_000_000)
gc.collect()
display = ILI9486(spi, pcs, pdc, prst)

plot = PLOT(display, 5, 5, 300, 200, padding=1, box_color=(255, 255, 255))


x = list(linspace(0, 8, 25))

y1 = [value**2 / 2 for value in x]
y2 = [2 + value**2 + 3 * value for value in x]

Fillbetween(plot, x, y1, y2, fill_color=(255, 0, 0))

display.show()
_images/fillbetween.jpg