Skip to main content

A simple plain-text, no-dependencies, pip-installable, open-source charting utility in Python.

Project description

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.bar or plainchart.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

Mean HTML chart

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plainchart-0.2.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

plainchart-0.2.1-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page