CircuitPython BoxPlot Library

uboxplot

Calculates boxplot and creates its graphical representation

  • Author: Jose D. Montoya

Implementation Notes

Hardware: Boards with CircuitPython >8.0.0 RC2

Software and Dependencies:

class uboxplot.Boxplot(*args: Any, **kwargs: Any)

A BoxPlot TileGrid. The origin is set using x and y.

Parameters:
  • data ((list, tuple)) – source data to calculate the boxplot

  • x (int) – x position of the boxplot origin

  • y (int) – y position of the boxplot origin

  • width (int) – requested width, in pixels. Defaults to 20 pixels.

  • height (int) – requested height, in pixels.

  • background_color (int) – background color to use defaults to black (0x000000)

  • fill_color (int) – background color to use defaults to black (0x000000)

  • line_color (int) – background color to use defaults to white (0xFFFFFF)

Quickstart: Importing and using UBoxplot

Here is one way of importing the Boxplot class so you can use it as the name Boxplot:

from uboxplot import Boxplot
import displayio

Now you can create a boxplot at pixel position x=20, y=30 using:

a=[1, 1, 4, 5, 6, 7, 7, 7, 8, 9, 10, 15, 16, 17, 24, 56, 76, 87, 87]
my_boxplot=Boxplot(a, x=50, y=50) # instance the boxplot at x=50, y=50
my_group = displayio.Group()

Once you set up your display, you can now add my_boxplot to your display.Group() using:

my_group.append(my_boxplot)
display.show(my_group) # add the group to the display

Summary: Boxplot Features and input variables

The uboxplot TileGrid has some options for controlling its position, visible appearance, through a collection of input variables:

  • position: x, y

  • size: width and height

  • color: background_color, fill_color, line_color

  • range: xrange and yrange This is the range in absolute units. For example, when using (20-90), the X axis will start at 20 finishing at 90. However, the height of the graph is given by the height parameter. The scale is handled internally to provide a 1:1 experience when you update the graph.

Diagram of the boxplot TileGrid with the pointer in motion.

This is a diagram of a boxplot

draw() None

This function draws the boxplot

Returns:

None

static find_points(data)

this function finds the quartiles, minimum and maximum for the box plot

Parameters:

data – data to be processed

Returns:

tuple with the values

static normalize(oldrangemin, oldrangemax, newrangemin, newrangemax, value)

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

Parameters:
  • oldrangemin – minimum of the original range

  • oldrangemax – maximum of the original range

  • newrangemin – minimum of the new range

  • newrangemax – maximum of the new range

  • value – value to be converted

Returns:

converted value

print_data() None

This function prints the quartiles data

Returns:

None