A text-based, no-dependencies, pip
-installable, open-source charting utility in Python.
Usage:
>>> import plainchart
>>> chart = plainchart.PlainChart([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) # π₯§
>>> print(chart.render())
β β
β β
β β
β β β
ββ ββ ββ
ββ ββ ββ
β ββ ββ ββ
β β ββ βββββ
β β ββββββββ
ββββββββββββ
To install PlainChart, you can use pipenv or pip:
$ pipenv install plainchart
With PlainChart, you can:
- render an array of values in a text-based chart
- limit the height of the chart and have the values rendered accordingly
- render a different style of chart, e.g.,
plainchart.PlainChart.bar
orplainchart.PlainChart.scatter
- implement your own style of chart, e.g.,
mean_html
(see example below)
>>> import plainchart
>>> import random
>>>
>>> values = [random.randint(0, 10) for _ in range(100)]
>>> chart = plainchart.PlainChart(values)
>>>
>>> print(chart.render())
β β β β β β β β
β β β ββ β β β β β β β β
β β ββ ββ β β ββ β β ββ β β β β β β β β β
β β ββ ββ βββ β ββ βββ β β β ββ β ββ β β β β β β β β β
β β βββ ββ βββ ββ ββ ββββ β β β β β ββ β ββ β β β β βββ β β β β
β β βββ ββ βββ ββ ββ ββββ ββ β β β β β ββ β ββ β ββ β βββββββ βββ β β
β β βββ ββ βββ ββ βββββββββ βββ β β β β β β β β ββ β ββ β ββ β βββββββ βββ ββ ββ
β β ββββ βββ ββββ ββββββββββββ βββ β β β β βββ β β ββ βββ β βββ β ββ βββββββββ βββ ββ β ββ
ββββ ββββ βββ ββββ ββββββββββββ βββ ββ β β βββββββ ββββββββ ββ βββββ ββββ βββββββββ βββ βββ ββββ
βββββ ββββ ββββββββ ββββββββββββββββ ββ β ββ βββββββββββββββββββββββββ ββββββββββββββ βββββββββββββ
>>> import plainchart
>>> import math
>>> import numpy as np
>>>
>>> values = [1.3 + math.sin(x) for x in np.linspace(0, 4 * math.pi, num=100)]
>>> chart = plainchart.PlainChart(values, style=plainchart.PlainChart.scatter)
>>>
>>> print(chart.render())
ΓΓΓΓΓΓΓΓ ΓΓΓΓΓΓΓ
ΓΓΓ ΓΓΓ ΓΓΓ ΓΓΓ
ΓΓ ΓΓ ΓΓΓ ΓΓ
ΓΓ ΓΓ Γ ΓΓ
ΓΓ ΓΓ ΓΓ ΓΓ Γ
Γ ΓΓ ΓΓ ΓΓ
ΓΓ ΓΓ ΓΓ ΓΓ
ΓΓΓ ΓΓ ΓΓ ΓΓ
ΓΓΓ ΓΓΓΓ ΓΓΓΓ ΓΓΓΓ
ΓΓΓΓΓ ΓΓΓΓ
You can also implement your own style of chart. Below is an example of a HTML chart (mean_html.py
) with different colors for values below and above the mean.
import plainchart
import random
import statistics
def mean_html(chart, value, y):
mean = statistics.mean(chart.values)
mean_y = chart.y(mean)
value_y = chart.y(value)
if value_y <= mean_y:
if y <= value_y:
return '<span style="color:green">β</span>'
return '<span style="color:white">β</span>'
else:
if y <= mean_y:
return '<span style="color:green">β</span>'
elif y <= value_y:
return '<span style="color:red">β</span>'
return '<span style="color:white">β</span>'
values = [random.randint(0, 10) for _ in range(100)]
chart = plainchart.PlainChart(values, style=mean_html)
print(chart.render(new_line='<br>'))
$ python mean_html.py > mean.html
Please feel free to open an issue to propose a new feature or point out a bug. You can also fork the PlainChart repository and submit a pull request.
PlainChart is free and under the MIT License. To support its development, you can make a donation to cash.me/$gduverger.