Skip to content

Commit 267f8a3

Browse files
committed
adding_bar_example
1 parent 0f3fc18 commit 267f8a3

File tree

7 files changed

+64
-96
lines changed

7 files changed

+64
-96
lines changed

circuitpython_uplot/ubar.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
__version__ = "0.0.0+auto.0"
2626
__repo__ = "https://github.com/adafruit/CircuitPython_uplot.git"
2727

28+
2829
# pylint: disable=too-many-arguments, invalid-name, protected-access
2930
# pylint: disable=too-few-public-methods, no-self-use, too-many-locals
3031
class ubar:
@@ -54,9 +55,14 @@ def __init__(
5455
:param bool projection: creates projection of the bars given them depth.
5556
5657
"""
57-
self._bar_space = bar_space
58-
self._graphx = abs(plot._newxmax - plot._newxmin) // (len(x) + 4)
59-
self._graphy = abs(plot._newymax - plot._newymin) // (max(y) + 2)
58+
y = [i * plot.scale for i in y]
59+
self._bar_space = int(bar_space / plot.scale)
60+
self._graphx = plot.scale * int(
61+
abs(plot._newxmax - plot._newxmin) / (len(x) + 4)
62+
)
63+
self._graphy = plot.scale * int(
64+
abs(plot._newymax - plot._newymin) / (max(y) + 2)
65+
)
6066
self._new_min = int(plot.transform(0, max(y), max(y), 0, 0))
6167
self._new_max = int(plot.transform(0, max(y), max(y), 0, max(y)))
6268

@@ -70,7 +76,7 @@ def __init__(
7076
width=self._graphx,
7177
height=self._graphy * y[i],
7278
x=xstart + (i * self._graphx),
73-
y=plot._newymin - self._graphy * y[i],
79+
y=int(plot._newymin - self._graphy * y[i] / plot.scale),
7480
color_index=plot._index_colorused,
7581
)
7682
)

circuitpython_uplot/uplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(
9393
print("Defaulting to y=0")
9494
y = 0
9595

96-
super().__init__(x=x, y=y, scale=1)
96+
super().__init__(x=x, y=y, scale=scale)
9797

9898
self._axesparams = "box"
9999

docs/bar_scale.jpg

16.3 KB
Loading

docs/conf.py

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
42
#
53
# SPDX-License-Identifier: MIT
@@ -12,41 +10,28 @@
1210

1311
# -- General configuration ------------------------------------------------
1412

15-
# Add any Sphinx extension module names here, as strings. They can be
16-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
17-
# ones.
1813
extensions = [
1914
"sphinx.ext.autodoc",
2015
"sphinx.ext.intersphinx",
2116
"sphinx.ext.napoleon",
2217
"sphinx.ext.todo",
2318
]
2419

25-
# Uncomment the below if you use native CircuitPython modules such as
26-
# digitalio, micropython and busio. List the modules you use. Without it, the
27-
# autodoc module docs will fail to generate with a warning.
28-
autodoc_mock_imports = ["displayio", "bitmaptools", "vectorio", "ulab", "terminalio"]
29-
3020
autodoc_preserve_defaults = True
3121

32-
3322
intersphinx_mapping = {
3423
"python": ("https://docs.python.org/3", None),
3524
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
3625
"ulab": ("https://micropython-ulab.readthedocs.io/en/latest/", None),
3726
}
3827

28+
autodoc_mock_imports = ["digitalio", "busio", "bitmaptools", "vectorio", "ulab"]
3929
# Show the docstring from both the class and its __init__() method.
4030
autoclass_content = "both"
41-
4231
# Add any paths that contain templates here, relative to this directory.
4332
templates_path = ["_templates"]
44-
4533
source_suffix = ".rst"
46-
47-
# The master toctree document.
4834
master_doc = "index"
49-
5035
# General information about the project.
5136
project = "CircuitPython uplot Library"
5237
creation_year = "2023"
@@ -68,11 +53,6 @@
6853
# The full version, including alpha/beta/rc tags.
6954
release = "1.0"
7055

71-
# The language for content autogenerated by Sphinx. Refer to documentation
72-
# for a list of supported languages.
73-
#
74-
# This is also used if you do content translation via gettext catalogs.
75-
# Usually you set "language" from the command line for these cases.
7656
language = "en"
7757

7858
# List of patterns, relative to source directory, that match files and
@@ -86,22 +66,11 @@
8666
"CODE_OF_CONDUCT.md",
8767
]
8868

89-
# The reST default role (used for this markup: `text`) to use for all
90-
# documents.
91-
#
9269
default_role = "any"
93-
94-
# If true, '()' will be appended to :func: etc. cross-reference text.
95-
#
9670
add_function_parentheses = True
97-
98-
# The name of the Pygments (syntax highlighting) style to use.
9971
pygments_style = "sphinx"
100-
10172
todo_include_todos = False
102-
103-
todo_emit_warnings = True
104-
73+
todo_emit_warnings = False
10574
napoleon_numpy_docstring = False
10675

10776
# -- Options for HTML output ----------------------------------------------
@@ -136,60 +105,3 @@
136105

137106
# Output file base name for HTML help builder.
138107
htmlhelp_basename = "CircuitPython_Uplot_Librarydoc"
139-
140-
# -- Options for LaTeX output ---------------------------------------------
141-
142-
latex_elements = {
143-
# The paper size ('letterpaper' or 'a4paper').
144-
# 'papersize': 'letterpaper',
145-
# The font size ('10pt', '11pt' or '12pt').
146-
# 'pointsize': '10pt',
147-
# Additional stuff for the LaTeX preamble.
148-
# 'preamble': '',
149-
# Latex figure (float) alignment
150-
# 'figure_align': 'htbp',
151-
}
152-
153-
# Grouping the document tree into LaTeX files. List of tuples
154-
# (source start file, target name, title,
155-
# author, documentclass [howto, manual, or own class]).
156-
latex_documents = [
157-
(
158-
master_doc,
159-
"CircuitPython_uplot_Library.tex",
160-
"CircuitPython uplot Library Documentation",
161-
author,
162-
"manual",
163-
),
164-
]
165-
166-
# -- Options for manual page output ---------------------------------------
167-
168-
# One entry per manual page. List of tuples
169-
# (source start file, name, description, authors, manual section).
170-
man_pages = [
171-
(
172-
master_doc,
173-
"CircuitPython_uplot_Library",
174-
"CircuitPython uplot Library Documentation",
175-
[author],
176-
1,
177-
),
178-
]
179-
180-
# -- Options for Texinfo output -------------------------------------------
181-
182-
# Grouping the document tree into Texinfo files. List of tuples
183-
# (source start file, target name, title, author,
184-
# dir menu entry, description, category)
185-
texinfo_documents = [
186-
(
187-
master_doc,
188-
"CircuitPython_uplot_Library",
189-
"CircuitPython uplot Library Documentation",
190-
author,
191-
"CircuitPython_uplot_Library",
192-
"One line description of project.",
193-
"Miscellaneous",
194-
),
195-
]

docs/examples.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ ubar example
7171
:lines: 5-
7272
.. image:: ../docs/uplot_ex8.jpg
7373

74+
Ubar Scale Example
75+
---------------------
76+
77+
Bar plot example showing how to use the scale
78+
79+
.. literalinclude:: ../examples/uplot_ubar_scale_example.py
80+
:caption: examples/uplot_ubar_scale_example.py
81+
:lines: 5-
82+
.. image:: ../docs/bar_scale.jpg
83+
84+
7485
Ubar 3D Example
7586
----------------
7687

docs/quick_start.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Options available are:
3737
* backround_color: Allows to change the background color. The default is black.
3838
* box_color: Allows to change the box color. Default is white.
3939
* padding: allows the user to give the plot area a pad. This is helpful if you are planning to include text and legends in the axes.
40-
* scale: scale of the plot.
40+
* scale: scale of the plot. This will allow a plot to be scaled up at a user defined rate. This is currently only available for logging and bar plots.
41+
4142

4243
We tell the microcontroller to display our plot:
4344

examples/uplot_ubar_scale_example.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import displayio
8+
from circuitpython_uplot.uplot import Uplot
9+
from circuitpython_uplot.ubar import ubar
10+
11+
# from uplot_examples import u8
12+
# Setting up the display
13+
display = board.DISPLAY
14+
15+
# Creating a group to add the two plots
16+
group = displayio.Group()
17+
18+
# Creating the plot objects
19+
plot_scale1 = Uplot(0, 0, 100, 100, 1, scale=1)
20+
plot_scale2 = Uplot(125, 0, 100, 100, 1, scale=2)
21+
22+
# Creating the data
23+
a = ["a", "b", "c", "d"]
24+
b = [3, 5, 1, 7]
25+
26+
# Creating the bar plot
27+
ubar(plot_scale1, a, b, 0xFF1000, True, bar_space=8, xstart=10)
28+
ubar(plot_scale2, a, b, 0xFF1000, True, bar_space=4, xstart=5)
29+
30+
# Plotting and showing the plot
31+
group.append(plot_scale1)
32+
group.append(plot_scale2)
33+
34+
display.show(group)
35+
36+
# Adding some wait time
37+
while True:
38+
time.sleep(1)

0 commit comments

Comments
 (0)