Microplot Library

plot

CircuitPython Plot Class

  • Author(s): Jose D. Montoya

Implementation Notes

Software and Dependencies:

class circuitpython_uplot.plot.Plot(*args: Any, **kwargs: Any)

Canvas Class to add different elements to the screen. The origin point set by x and y properties

Parameters:
  • x (int) – origin x coordinate

  • y (int) – origin y coordinate

  • width (int) – plot box width in pixels

  • height (int) – plot box height in pixels

  • padding (int) – padding for the plot box in all directions

  • show_box (bool) – select if the plot box is displayed

  • background_color (int) – background color in HEX. Defaults to black 0x000000

  • box_color (int) – allows to choose the box line color. Defaults to white ‘’0xFFFFFF``

  • tickx_height (int) – x axes tick height in pixels. Defaults to 8.

  • ticky_height (int) – y axes tick height in pixels. Defaults to 8.

  • scale (int) – scale of the plot. Defaults to 1.

axs_params(axstype: Literal['box', 'cartesian', 'line'] = 'box') None

Setting up axs visibility

Parameters:

axstype (str) – argument with the kind of axs you selected

Returns:

None

draw_circle(radius: int = 5, x: int = 100, y: int = 100) None

Draw a circle in the plot area. This function is kept here for historical reasons. Please use scatter() instead.

Parameters:
  • radius (int) – circle radius

  • x (int) – circles center x coordinate position in pixels, Defaults to 100.

  • y (int) – circles center y coordinate position in pixels. Defaults to 100.

Returns:

None

show_text(text: str, x: int, y: int, anchorpoint: Tuple = (0.5, 0.0), text_color: int | None = None, free_text: bool = False, font=None) None

Show desired text in the screen :param str text: text to be displayed :param int x: x coordinate :param int y: y coordinate :param Tuple anchorpoint: Display_text anchor point. Defaults to (0.5, 0.0) :param int color: text color. Defaults to None :param bool free_text: Select to show free text :param font: font to be used. Defaults to None :return: None

tick_params(show_ticks=True, tickx_height: int = 8, ticky_height: int = 8, tickcolor: int = 0xFFFFFF, tickgrid: bool = False, showtext: bool = False, decimal_points: int = 0) None

Function to set ticks parameters

Parameters:
  • show_ticks (bool) – Show ticks. Defaults to True

  • tickx_height (int) – X axes tick height in pixels. Defaults to 8

  • ticky_height (int) – Y axes tick height in pixels. Defaults to 8

  • tickcolor (int) – tick color in hex. Defaults to white. 0xFFFFFF

  • tickgrid (bool) – defines if the grid is to be shown. Defaults to False

  • showtext (bool) – Show Axes text. Defaults to False

  • decimal_points (int) – Number of decimal points to show. Defaults to 0

Returns:

None

static transform(oldrangemin: float | int, oldrangemax: float | int, newrangemin: float | int, newrangemax: float | int, value: float | int) float | int

This function converts the original value into a new defined value in the new range

Parameters:
  • oldrangemin (int|float) – minimum of the original range

  • oldrangemax (int|float) – maximum of the original range

  • newrangemin (int|float) – minimum of the new range

  • newrangemax (int|float) – maximum of the new range

  • value (int|float) – value to be converted

Return int|float:

converted value

class circuitpython_uplot.plot.color

Class to define colors in HEX

scatter

CircuitPython scatter graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.scatter.Pointer

Pointer container class

class circuitpython_uplot.scatter.Scatter(plot: Plot, x: list | ulab.numpy.linspace | ulab.numpy.ndarray, y: list | ulab.numpy.linspace | ulab.numpy.ndarray, rangex: list | None = None, rangey: list | None = None, radius: list | int | None = 3, pointer_color: int = 0xFF905D, pointer: str | None = None, nudge: bool = True)

Main class to display different graphics

Parameters:
  • plot – Plot object for the scatter to be drawn

  • x – x points coordinates

  • y – y points coordinates

  • rangex (list|None) – x range limits

  • rangey (list|None) – y range limits

  • radius (int|list) – circle radius

  • pointer_color (int) – pointer color. Default is 0xFF905D

  • pointer (str|None) – pointer shape.

  • nudge (bool) – moves the graph a little for better displaying

bar

CircuitPython scatter graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.bar.Bar(plot: Plot, x: list, y: list, color: int = 0xFFFFFF, fill: bool = False, bar_space=16, xstart=50, projection=False, color_palette=None, max_value=None)

Main class to display different graphics

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • x (list) – x data

  • y (list) – y data

  • color (int) – boxes color. Defaults to const:0xFFFFFF

  • fill (bool) – boxes fill attribute. Defaults to False

  • bar_space (int) – space in pixels between the bars

  • xstart (int) – start point in the x axis for the bar to start. Defaults to 50

  • projection (bool) – creates projection of the bars given them depth.

  • color_palette (list) – list of colors to be used for the bars. Defaults to None. Be aware that you need to include the same number if colors as your data. This functionality will only work with filled bars.

  • max_value (int) – for filled unprojected bars will setup the maxium value for the bars. This allows the user to update the bars in real-time. There is an example in the examples folder showing this functionality

update_bar_color(bar_number: int, color: int = 0xFFFFFF)

Update the color of a single bar

Parameters:
  • bar_number (int) – bar index. Bar number starts with :const`0`

  • color (int) – new bar color. Defaults to 0xFFFFFF. White

update_colors(colors: list = None)

Update Colors of the bars

Parameters:

colors (list) – list of colors to be asigned. list lenght must coincide with the numbers of bars in your plot

update_values(values: list = None)

Update Values of the bars

circuitpython_uplot.bar.color_fader(source_color=None, brightness=1.0, gamma=1.0)

Function taken from https://github.com/CedarGroveStudios Copyright (c) 2022 JG for Cedar Grove Maker Studios License: MIT

Scale a 24-bit RGB source color value in proportion to the brightness setting (0 to 1.0). Returns an adjusted 24-bit RGB color value or None if the source color is None (transparent). The adjusted color’s gamma value is typically from 0.0 to 2.0 with a default of 1.0 for no gamma adjustment.

Parameters:
  • source_color (int) – The color value to be adjusted. Default is None.

  • brightness (float) – The brightness value for color value adjustment. Value range is 0.0 to 1.0. Default is 1.0 (maximum brightness).

  • gamma (float) – The gamma value for color value adjustment. Value range is 0.0 to 2.0. Default is 1.0 (no gamma adjustment).

Return int:

The adjusted color value.

pie

CircuitPython pie graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.pie.Pie(plot: Plot, data: list, x: int = 0, y: int = 0, radius: int = 40)

Class to draw pie

Parameters:
  • plot (Plot) – Plot object for the pie to be drawn

  • data (list) – data to make the pie

  • x (int) – pie center x coordinate

  • y (int) – pie center y coordinate

  • radius (int) – pie radius

get_points(x: int, y: int, radius: int, angle: float) None
Parameters:
  • x (int) – center x coordinate

  • y (int) – center y coordinate

  • radius (int) – pie radius in pixels

  • angle (flaot) – line angle

Returns:

None

cartesian

CircuitPython cartesian graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.cartesian.Cartesian(plot: Plot, x: list | ulab.numpy.linspace | ulab.numpy.ndarray, y: list | ulab.numpy.linspace | ulab.numpy.ndarray, rangex: list | None = None, rangey: list | None = None, line_color: int | None = None, line_style: str | None = None, ticksx: ulab.numpy.array | list = None, ticksy: ulab.numpy.array | list = None, fill: bool = False, nudge: bool = True, logging: bool = False)

Class to draw cartesian plane

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • x (list|ulab.numpy.linspace|ulab.numpy.ndarray) – x points coordinates

  • y (list|ulab.numpy.linspace|ulab.numpy.ndarray) – y points coordinates

  • rangex (list|None) – x range limits. Defaults to None

  • rangey (list|None) – y range limits. Defaults to None

  • line_color (int|None) – line color. Defaults to None

  • line_style (str|None) – line style. Defaults to None

  • ticksx (np.array|list) – X axis ticks values

  • ticksy (np.array|list) – Y axis ticks values

  • fill (bool) – Show the filling. Defaults to False

  • nudge (bool) – moves the graph a little for better displaying. Defaults to True

  • logging (bool) – used to change the logic of the cartesian to work as a logger

class circuitpython_uplot.cartesian.LineStyle

Line style class

fillbetween

CircuitPython fillbetween graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.fillbetween.Fillbetween(plot: Plot, x: list | ulab.numpy.linspace | ulab.numpy.ndarray, y1: list | ulab.numpy.linspace | ulab.numpy.ndarray, y2: list | ulab.numpy.linspace | ulab.numpy.ndarray, rangex: list | None = None, rangey: list | None = None, fill_color: int = 0xF6FF41, nudge: bool = True)

Class to draw a fillbetween graph

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • x (list|ulab.numpy.linspace|ulab.numpy.ndarray) – x points coordinates

  • y1 (list|ulab.numpy.linspace|ulab.numpy.ndarray) – y1 points coordinates

  • y2 (list|ulab.numpy.linspace|ulab.numpy.ndarray) – y2 points coordinates

  • rangex (list|None) – x range limits

  • rangey (list|None) – y range limits

  • fill_color (int) – filling color. Defaults to 0xF6FF41

  • nudge (bool) – moves the graph a little for better displaying

map

CircuitPython color map graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.map.Map(plot: Plot, data_points: ulab.numpy.ndarray, initial_color: int, final_color: int)

Main class to display different graphics

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • data_points (np.array) – data points to create the color map

  • initial_color (int) – initial color to create the color map

  • final_color (int) – final color to create the color map

circuitpython_uplot.map.color_fade(start_color: int, end_color: int, fraction: float)

Linear extrapolation of a color between two RGB colors (tuple or 24-bit integer).

Parameters:
  • start_color – starting color

  • end_color – ending color

  • fraction – Floating point number ranging from 0 to 1 indicating what fraction of interpolation between start_color and end_color.

circuitpython_uplot.map.color_to_tuple(value: int)

Converts a color from a 24-bit integer to a tuple.

Parameters:

value – RGB desired value - can be a RGB tuple or a 24-bit integer.

logging

CircuitPython logging data graph

  • Author: Jose D. Montoya

class circuitpython_uplot.logging.Logging(plot: Plot, x: list | ulab.numpy.linspace | ulab.numpy.ndarray, y: list | ulab.numpy.linspace | ulab.numpy.ndarray, rangex: list, rangey: list, line_color: int = 0xFFFFFF, ticksx: ulab.numpy.array | list = np.array([0, 10, 30, 50, 70, 90]), ticksy: ulab.numpy.array | list = np.array([0, 10, 30, 50, 70, 90]), tick_pos: bool = False, fill: bool = False, limits: list | None = None, limits_color: int = 0xFF0000)

Class to log data

Parameters:
  • plot (Plot) – Plot object for the log to be drawn

  • x (list|ulab.numpy.linspace|ulab.numpy.ndarray) – x points coordinates

  • y (list|ulab.numpy.linspace|ulab.numpy.ndarray) – y points coordinates

  • rangex (list|None) – x range limits. Defaults to None

  • rangey (list|None) – y range limits. Defaults to None

  • line_color (int|None) – line color. Defaults to None

  • ticksx (np.array|list) – X axis ticks values

  • ticksy (np.array|list) – Y axis ticks values

  • tick_pos (bool) – indicates ticks position. True for below the axes. Defaults to False

  • fill (bool) – enable the filling of the plot. Defaults to False

static clear_plot(plot) None

Clears the plot area

draw_new_lines(plot: Plot, x: list, y: list, fill: bool = False) None

Draw the plot lines :param Plot plot: plot object provided :param list x: list of x values :param list y: list of y values :param bool fill: parameter to fill the plot graphic. Defaults to False :return: None

draw_points(plot: Plot, x: list, y: list, fill: bool = False) None

Draws points in the plot :param Plot plot: plot object provided :param list x: list of x values :param list y: list of y values :param bool fill: parameter to fill the plot graphic. Defaults to False :return: None

svg

CircuitPython svg icon utility for CircuitPython_uplot

  • Author(s): Jose D. Montoya

class circuitpython_uplot.svg.SVG(plot: Plot, icon: dict, x: int, y: int, factor: float, color: int = 0xFFFFFF)

class to render svg images in the plot area

Parameters:
  • plot (Plot) – Plot object for the log to be drawn

  • icon (dictionary) – icon dictionary

  • x (int) – x position for the svg image

  • y (int) – y position for the svg image

  • factor (float) – scale factor for the svg

  • color – color of the svg file. Defaults to White, 0xFFFFFF

shade

CircuitPython shade utility for Plotting.

  • Author(s): Jose D. Montoya

class circuitpython_uplot.shade.shade(plot: Plot, x: list | ulab.numpy.linspace | ulab.numpy.ndarray, y1: list, y2: list, rangex: list | None = None, rangey: list | None = None, fill_color: int = 0xF6FF41, nudge: bool = True)

Class to draw shade between two lines

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • x (list|ulab.numpy.linspace|ulab.numpy.ndarray) – x points coordinates

  • y1 (list) – y1 points coordinates

  • y2 (list) – y2 points coordinates

  • rangex (list|None) – x range limits

  • rangey (list|None) – y range limits

  • fill_color (int) – filling color. Defaults to 0xF6FF41

  • nudge (bool) – moves the graph a little for better displaying

polar

CircuitPython Polar graph

  • Author(s): Jose D. Montoya

class circuitpython_uplot.polar.Polar(plot: Plot, radius: list | ulab.numpy.linspace | ulab.numpy.ndarray, theta: list | ulab.numpy.linspace | ulab.numpy.ndarray, rangex: list | None = None, rangey: list | None = None, line_color: int | None = None, polar_plot_line_color: int = 0x647182, nudge: bool = True, radius_ticks: list = [1.0, 2.0])

Class to draw polar plots

Parameters:
  • plot (Plot) – Plot object for the scatter to be drawn

  • radius (list|ulab.numpy.linspace|ulab.numpy.ndarray) – radius points

  • theta (list|ulab.numpy.linspace|ulab.numpy.ndarray) – theta points

  • rangex (list|None) – x range limits. Defaults to None

  • rangey (list|None) – y range limits. Defaults to None

  • line_color (int|None) – line color. Defaults to None

  • fill (bool) – Show the filling. Defaults to False

  • nudge (bool) – moves the graph a little for better displaying. Defaults to True