PlainChart
A simple plain-text, 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())
▌ ▌
▌ ▌
▌ ▌
▌ ▌ ▌
▌▌ ▌▌ ▌▌
▌▌ ▌▌ ▌▌
▌ ▌▌ ▌▌ ▌▌
▌ ▌ ▌▌ ▌▌▌▌▌
▌ ▌ ▌▌▌▌▌▌▌▌
▌▌▌▌▌▌▌▌▌▌▌▌
Installation
To install PlainChart, you can use pipenv or pip:
$ pipenv install plainchart
Features
With PlainChart, you can:
- render an array of values in a plain text chart
- limit the height of the chart and have the values rendered accordingly
- render a different style of chart, e.g.,
plainchart.PlainChart.barorplainchart.PlainChart.scatter - implement your own style of chart, e.g.,
mean_html(see example below)
Examples
>>> 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
Contribute
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.
Support
PlainChart is free and under the MIT License. To support its development, you can make a donation to cash.me/$gduverger.
Metadata
Release files for plainchart 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| plainchart-0.2.1.tar.gz | 3.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| plainchart-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.1 kB
Release files / plainchart-0.2.1.tar.gz
| Download URL | plainchart-0.2.1.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27b0aef82d2b80c76ecb3e00ad162daa9490945e6400d91ceab1c91643bfb81b
|
|
BLAKE2b-256 checksum How to use checksums |
9afd97e94f5f4398d74597d23173e42819b03505a7dcc93c9d6cd95860e46a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Release files / plainchart-0.2.1-py3-none-any.whl
| Download URL | plainchart-0.2.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef99c009dfef2cd7e5dd28fef01e284f337bb22ca4b499dfcaa8bdd819164c19
|
|
BLAKE2b-256 checksum How to use checksums |
040550ff85624076396dbc1bc3569d495d89fe68c2506f6c7e3240edf9876334
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Security for plainchart 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.