Skip to content

Commit

Permalink
Add tick_point_color arg; Configure README.md; 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Feb 22, 2023
1 parent c276ba8 commit 95002a5
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 31 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Downloads](https://pepy.tech/badge/asciiplot)](https://pepy.tech/project/asciiplot)
[![GitHub](https://img.shields.io/github/license/w2sv/asciiplot?)](https://github.com/w2sv/asciiplot/blob/master/LICENSE)

#### Platform-agnostic, highly customizable sequence plotting in the console
__Platform-agnostic, highly customizable sequence plotting in the console__
![alt text](https://github.com/w2sv/asciiplot/blob/master/assets/sin&cos.png?raw=true)

## Installation
Expand All @@ -18,11 +18,12 @@ pip install asciiplot

## Plot Appearance Configuration Options

Set:
You may set the/a
- chart height & title
- the color of virtually all chart components and areas, picked from a wide array of shades due to the integration of [colored](https://pypi.org/project/colored/)
- consistent margin between consecutive data points to widen your chart
- the chart indentation within its hosting terminal, or whether it ought to be centered in it, respectively
- color of virtually all chart components and areas, picked from a wide array of shades due to the integration of [colored](https://pypi.org/project/colored/)
- margin between consecutive data points to widen your chart
- tick point color, to make the tick points visually stand out in case of a margin having been set
- chart indentation within its hosting terminal, or whether it ought to be centered in it, respectively
- axes descriptions
- x-axis tick labels, which may be set to contain strings instead of just numeric values
- y-axis tick label decimal places
Expand All @@ -35,11 +36,12 @@ from asciiplot import asciiize, Color

print(
asciiize(
[1, 1, 2, 3, 5, 8, 13, 21],
[0, 1, 1, 2, 3, 5, 8, 13, 21],
sequence_colors=[Color.BLUE_3B],
height=21,
height=22,
inter_points_margin=5,
background_color=Color.LIGHT_SALMON_1,
tick_point_color=Color.RED_1,
label_color=Color.BLUE_VIOLET,
label_background_color=Color.DEEP_PINK_3A,
title='Fibonacci',
Expand Down Expand Up @@ -75,7 +77,7 @@ print(
```
![alt text](https://github.com/w2sv/asciiplot/blob/master/assets/random.png?raw=true)

## Acknowledgements
## Credits
Core sequence asciiization algorithm adopted from [asciichartpy](https://github.com/kroitor/asciichart/blob/master/asciichartpy/)

## Run Tests
Expand Down
2 changes: 2 additions & 0 deletions asciiplot/_asciiization.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def asciiize(*sequences: List[float],
inter_points_margin: int = 0,

sequence_colors: Sequence[Color] = (Color.DEFAULT,),
tick_point_color: Color = Color.DEFAULT,
background_color: Color = Color.DEFAULT,
label_color: Color = Color.DEFAULT,
label_background_color: Color = Color.DEFAULT,
Expand Down Expand Up @@ -119,6 +120,7 @@ def asciiize(*sequences: List[float],
inter_points_margin=inter_points_margin,
n_points=max_element_length(sequences),
sequence_colors=sequence_colors,
tick_point_color=tick_point_color,
background_color=background_color,
label_color=label_color,
x_axis_tick_label_input=x_axis_tick_labels,
Expand Down
17 changes: 12 additions & 5 deletions asciiplot/_chart/grid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from more_itertools import pairwise

from asciiplot._coloring import Color
from asciiplot._chart.grid.cell import Cell
from asciiplot._config import Config
from asciiplot._params import Params
Expand Down Expand Up @@ -35,16 +36,20 @@ def __init__(self, config: Config, params: Params):
def add_sequences(self, sequences: PlotSequences):
for i_sequence, sequence in enumerate(sequences):
sequence_color = self._config.sequence_colors[i_sequence % len(self._config.sequence_colors)]
tick_point_color = sequence_color if self._config.tick_point_color is Color.DEFAULT else self._config.tick_point_color

# add '┼' at beginning where sequence overlaps with y-axis
self._cell_at(self._x_grid_domain(sequence[0]), 0).set_foreground('┼', sequence_color)
self._cell_at(self._x_grid_domain(sequence[0]), 0).set_foreground('┼', tick_point_color)

for col_index, (x1_value_domain, x2_value_domain) in enumerate(pairwise(sequence)):
set_cell = lambda x, segment: self._cell_at(x, col_index + 1).set_foreground(segment, sequence_color)
y = col_index + 1
set_cell = lambda x, segment: self._cell_at(x, y).set_foreground(segment, sequence_color)

x1 = self._x_grid_domain(x1_value_domain)
x2 = self._x_grid_domain(x2_value_domain)

x_min, x_max = sorted([x1, x2])

if x1 == x2:
set_cell(x1, '─')
else:
Expand All @@ -57,10 +62,12 @@ def add_sequences(self, sequences: PlotSequences):
set_cell(x2, segment_x2)

# add vertical segments if applicable
x_min, x_max = sorted([x1, x2])
for x in range(x_min + 1, x_max):
set_cell(x, '│')

if self._is_tick_point(y):
self._cell_at(x_max, y).fg = tick_point_color

def _cell_at(self, x: int, y: int) -> Cell:
return self[self._last_row_index - x][y]

Expand All @@ -78,7 +85,7 @@ def add_x_axis(self):
# to one comprising both the sequence and axis segment in color
# of respective sequence

is_data_point = self._is_data_point(i)
is_data_point = self._is_tick_point(i)

if cell.is_empty:
self[-1][i].replace_string('┬' if is_data_point else '─')
Expand Down Expand Up @@ -115,7 +122,7 @@ def add_y_axis_with_tick_labels(self):
)
)

def _is_data_point(self, point_index: int) -> bool:
def _is_tick_point(self, point_index: int) -> bool:
""" Returns:
boolean, indicating whether point corresponding to point_index is actual
data point denoted in original sequences, instead of interpolated
Expand Down
1 change: 1 addition & 0 deletions asciiplot/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Config:
n_points: int

sequence_colors: Sequence[Color]
tick_point_color: Color
background_color: Color
label_color: Color

Expand Down
Binary file modified assets/fibonacci.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/random.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/sin&cos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 49 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "asciiplot"
version = "0.1.7"
description = "Platform-agnostic, highly customizable sequence plotting in console"
version = "1.0.0"
description = "Platform-agnostic, highly customizable sequence plotting in the console"
authors = ["w2sv <[email protected]>"]
license = "MIT"
repository = "https://github.com/w2sv/asciiplot"
Expand Down
39 changes: 24 additions & 15 deletions tests/examine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# y_axis_tick_label_decimal_places=2
# )

print()

x = np.linspace(0, 2 * np.pi, 10)
y_sin = [np.sin(x_i) for x_i in x]
y_cos = [np.cos(x_i) for x_i in x]
Expand All @@ -28,7 +30,7 @@
asciiize(
y_sin,
y_cos,
title="Sin & Cos",
# title="Sin & Cos",
title_color=Color.DARK_GOLDENROD,
sequence_colors=[Color.PURPLE_3, Color.RED_1],
background_color=Color.BLACK,
Expand All @@ -50,6 +52,7 @@
inter_points_margin=5,
sequence_colors=[Color.BLUE_3B],
label_color=Color.BLUE_VIOLET,
tick_point_color=Color.RED_1,
title='Fibonacci',
title_color=Color.RED_1,
center_horizontally=True,
Expand All @@ -60,17 +63,23 @@
)
)

# chart = asciiize(
# [17, 21, 19, 19, 5, 7, 12, 4],
# [7, 8, 3, 17, 19, 18, 5, 2, 20],
# sequence_colors=[Color.RED, Color.BLUE_VIOLET],
# inter_points_margin=5,
# height=20,
# background_color=Color.GREY_7,
# title='Random Sequences',
# title_color=Color.MEDIUM_PURPLE,
# label_color=Color.MEDIUM_PURPLE,
# x_axis_description='x',
# y_axis_description='y',
# center_horizontally=True
# )
print('\n' * 3)

print(
asciiize(
[17, 21, 19, 19, 5, 7, 12, 4],
[7, 8, 3, 17, 19, 18, 5, 2, 20],
sequence_colors=[Color.RED, Color.BLUE_VIOLET],
inter_points_margin=5,
height=20,
background_color=Color.GREY_7,
title='Random Sequences',
title_color=Color.MEDIUM_PURPLE,
label_color=Color.MEDIUM_PURPLE,
x_axis_description='x',
y_axis_description='y',
center_horizontally=True
)
)

print('\n' * 3)

0 comments on commit 95002a5

Please sign in to comment.