Skip to content

Commit

Permalink
adding tick_height_argument argument for boxplot
Browse files Browse the repository at this point in the history
  • Loading branch information
jposada202020 committed Mar 8, 2023
1 parent 0ac6332 commit 25dc1dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
29 changes: 19 additions & 10 deletions circuitpython_uplot/uplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Uplot(displayio.Group):
:param bool show_box: select if the plot box is displayed
:param int background_color: background color in HEX. Defaults to black ``0x000000``
:param int box_color: allows to choose the box line color. Defaults to white ''0xFFFFFF``
:param int tickx_height: x axes tick height in pixels. Defaults to 8.
:param int ticky_height: y axes tick height in pixels. Defaults to 8.
"""

Expand All @@ -69,6 +71,8 @@ def __init__(
show_box: bool = True,
background_color: int = 0x000000,
box_color: int = 0xFFFFFF,
tickx_height: int = 8,
ticky_height: int = 8,
) -> None:
if width not in range(50, 481):
print("Be sure to verify your values. Defaulting to width=100")
Expand Down Expand Up @@ -107,7 +111,8 @@ def __init__(

self._showtext = False

self._tickheight = 8
self._tickheightx = tickx_height
self._tickheighty = ticky_height
self._tickcolor = 0xFFFFFF
self._showticks = False
self._tickgrid = False
Expand Down Expand Up @@ -301,7 +306,7 @@ def _draw_ticks(self, x: int, y: int) -> None:
tick,
self._newymin,
tick,
self._newymin - self._tickheight,
self._newymin - self._tickheightx,
2,
)
if self._showtext:
Expand All @@ -313,7 +318,7 @@ def _draw_ticks(self, x: int, y: int) -> None:
self._plotbitmap,
self._newxmin,
tick,
self._newxmin + self._tickheight,
self._newxmin + self._tickheighty,
tick,
2,
)
Expand All @@ -327,15 +332,15 @@ def _draw_ticks(self, x: int, y: int) -> None:
tick,
self._newymin,
tick,
self._newymin - self._tickheight // 2,
self._newymin - self._tickheightx // 2,
2,
)
for tick in subticksyrenorm:
draw_line(
self._plotbitmap,
self._newxmin,
tick,
self._newxmin + self._tickheight // 2,
self._newxmin + self._tickheighty // 2,
tick,
2,
)
Expand All @@ -346,24 +351,28 @@ def _draw_ticks(self, x: int, y: int) -> None:

def tick_params(
self,
tickheight: int = 8,
tickx_height: int = 8,
ticky_height: int = 8,
tickcolor: int = 0xFFFFFF,
tickgrid: bool = False,
showtext: bool = False,
) -> None:
"""
Function to set ticks parameters
:param int tickheight: tick height in pixels
:param int tickcolor: tick color in hex
:param bool tickgrid: defines if the grid is to be shown
:param int tickx_height: X axes tick height in pixels. Defaults to 8
:param int ticky_height: Y axes tick height in pixels. Defaults to 8
:param int tickcolor: tick color in hex. Defaults to white. ``0xFFFFFF``
:param bool tickgrid: defines if the grid is to be shown. Defaults to `False`
:param bool showtext: Show Axes text. Defaults to `False`
:return: None
"""

self._showticks = True
self._tickheight = tickheight
self._tickheightx = tickx_height
self._tickheighty = ticky_height
self._plot_palette[2] = tickcolor
self._tickgrid = tickgrid
self._showtext = showtext
Expand Down
9 changes: 5 additions & 4 deletions docs/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ to use the correct keyword in the `Uplot.axs_params` function:

.. py:function:: Uplot.axs_params(axstype: Literal["box", "cartesian", "line"] = "box")
:param tickheight: Option to display the axes
:param axstype: Option to display the axes

Options available are:
* box : draws a box
Expand All @@ -111,16 +111,17 @@ the following parameters:

.. py:function:: Uplot.tick_params(tickheight, tickcolor, tickgrid)
:param int tickheight: tickheight in pixels
:param int tickx_height: tickx_height in pixels
:param int ticky_height: ticky_height in pixels
:param int tickcolor: tickcolor in Hex format
:param bool tickgrid: displays the tickgrid. Defaults to `False`

.. code-block:: python
plot.tick_params(tickheight=12, tickcolor=0xFF0008)
plot.tick_params(tickx_height=12, tickcolor=0xFF0008)
Gridlines are normally off. If you want visible gridlines then use:
Gridlines are normally ``OFF``. If you want visible gridlines then use:

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion examples/uplot_tickparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)

# Setting up tick parameters
plot.tick_params(tickheight=12, tickcolor=color.BLACK, tickgrid=True)
plot.tick_params(tickx_height=12, ticky_height=6, tickcolor=color.BLACK, tickgrid=False)
# Seeting some date to plot
x = np.linspace(-4, 4, num=50)
constant = 1.0 / np.sqrt(2 * np.pi)
Expand Down

0 comments on commit 25dc1dc

Please sign in to comment.