Skip to content

Commit 0ac6332

Browse files
committed
adding line_color argument for boxplot
1 parent 341ddd0 commit 0ac6332

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

circuitpython_uplot/uplot.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Uplot(displayio.Group):
5555
:param int padding: padding for the plot box in all directions
5656
:param bool show_box: select if the plot box is displayed
5757
:param int background_color: background color in HEX. Defaults to black ``0x000000``
58+
:param int box_color: allows to choose the box line color. Defaults to white ''0xFFFFFF``
5859
5960
"""
6061

@@ -67,6 +68,7 @@ def __init__(
6768
padding: int = 25,
6869
show_box: bool = True,
6970
background_color: int = 0x000000,
71+
box_color: int = 0xFFFFFF,
7072
) -> None:
7173
if width not in range(50, 481):
7274
print("Be sure to verify your values. Defaulting to width=100")
@@ -126,7 +128,7 @@ def __init__(
126128

127129
self._plot_palette = displayio.Palette(14)
128130
self._plot_palette[0] = background_color
129-
self._plot_palette[1] = 0xFFFFFF
131+
self._plot_palette[1] = box_color
130132
self._plot_palette[2] = self._tickcolor
131133
self._plot_palette[3] = self._barcolor
132134
self._plot_palette[4] = 0x149F14 # Pie Chart color 1
@@ -439,3 +441,17 @@ def show_text(
439441
text_toplot.anchor_point = anchorpoint
440442
text_toplot.anchored_position = (x, y)
441443
self.append(text_toplot)
444+
445+
446+
# pylint: disable=missing-class-docstring, too-few-public-methods, invalid-name
447+
class color:
448+
WHITE = 0xFFFFFF
449+
BLACK = 0x000000
450+
RED = 0xFF0000
451+
GREEN = 0x00FF00
452+
BLUE = 0x0000FF
453+
PURPLE = 0x440044
454+
YELLOW = 0xFFFF00
455+
ORANGE = 0xFF9933
456+
TEAL = 0x158FAD
457+
GRAY = 0x808080

docs/quick_start.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Every one of them with different characteristics or graphs.
3333

3434
Options available are:
3535
* backround_color: Allows to change the background color. The default is black.
36+
* box_color: Allows to change the box color. Default is white.
3637

3738
We tell the microcontroller to display our plot:
3839

@@ -58,6 +59,7 @@ At the moment the following objects can be added to the plot area:
5859
* Stackplot
5960
* Bar graph
6061
* Pie Chart
62+
* Colormap
6163
* Display_shapes library objects
6264
* Histograms from the uhistogram library
6365
* Boxplots from the uboxplot library
@@ -125,6 +127,33 @@ Gridlines are normally off. If you want visible gridlines then use:
125127
plot.tick_params(tickgrid=True)
126128
127129
130+
Colors
131+
===============
132+
You can choose some colors directly from the library. This can be done by importing the color class:
133+
134+
.. code-block:: python
135+
136+
from circuitpython_uplot.uplot import color
137+
138+
This will allow you to use the colors in the list as color variable definitions
139+
140+
* WHITE
141+
* BLACK
142+
* RED
143+
* GREEN
144+
* BLUE
145+
* PURPLE
146+
* YELLOW
147+
* ORANGE
148+
* TEAL
149+
* GRAY
150+
151+
.. code-block:: python
152+
153+
plot = Uplot(0, 0, display.width, display.height, background_color=color.WHITE, box_color=color.BLACK)
154+
155+
156+
128157
===========
129158
Cartesian
130159
===========

examples/uplot_tickparameters.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,34 @@
55
import time
66
import board
77
from ulab import numpy as np
8-
from circuitpython_uplot.uplot import Uplot
8+
from circuitpython_uplot.uplot import Uplot, color
9+
from circuitpython_uplot.ucartesian import ucartesian
10+
911

1012
# Setting up the display
1113
display = board.DISPLAY
1214

1315
# Setting up the plot area
14-
plot = Uplot(0, 0, display.width, display.height)
16+
plot = Uplot(
17+
0,
18+
0,
19+
display.width,
20+
display.height,
21+
background_color=color.WHITE,
22+
box_color=color.BLACK,
23+
)
1524

1625
# Setting up tick parameters
17-
plot.tick_params(tickheight=12, tickcolor=0xFF00FF, tickgrid=True)
18-
26+
plot.tick_params(tickheight=12, tickcolor=color.BLACK, tickgrid=True)
1927
# Seeting some date to plot
2028
x = np.linspace(-4, 4, num=50)
2129
constant = 1.0 / np.sqrt(2 * np.pi)
2230
y = constant * np.exp((-(x**2)) / 2.0)
2331

32+
# Drawing the graph
33+
ucartesian(plot, x, y, line_color=color.BLACK)
34+
2435
# Plotting and showing the plot
25-
plot.draw_plot(x, y)
2636
display.show(plot)
2737

2838
# Adding some wait time

0 commit comments

Comments
 (0)