All Projects → deeplook → sparklines

deeplook / sparklines

Licence: GPL-3.0 license
Text-based sparkline command line mimicking those of Edward Tuft.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to sparklines

corona cases
🦠 Coronavirus Information on Telegram Chatbot
Stars: ✭ 19 (-77.38%)
Mutual labels:  graphs
graphql
A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
Stars: ✭ 397 (+372.62%)
Mutual labels:  graphs
cavernos
Retro fantasy terminal for building DOS-era ASCII games, powered by WebAssembly
Stars: ✭ 32 (-61.9%)
Mutual labels:  ascii
ldbc snb docs
Specification of the LDBC Social Network Benchmark suite
Stars: ✭ 39 (-53.57%)
Mutual labels:  graphs
outfancy
Python3 library to print tables in Terminal.
Stars: ✭ 47 (-44.05%)
Mutual labels:  ascii
CovidIndiaStats
A dashboard to visualise the spread of covid19 in India(state and districtwise) and around the world(countrywise).
Stars: ✭ 22 (-73.81%)
Mutual labels:  graphs
Advanced-Shortest-Paths-Algorithms
Java Code for Contraction Hierarchies Algorithm, A-Star Algorithm and Bidirectional Dijkstra Algorithm. Tested and Verified Code.
Stars: ✭ 63 (-25%)
Mutual labels:  graphs
gfapy
Gfapy: a flexible and extensible software library for handling sequence graphs in Python
Stars: ✭ 54 (-35.71%)
Mutual labels:  graphs
js-data-structures
🌿 Data structures for JavaScript
Stars: ✭ 56 (-33.33%)
Mutual labels:  graphs
pendfetch
Double Pendulum visualised with fetching system information in Python.
Stars: ✭ 62 (-26.19%)
Mutual labels:  ascii
ntds 2019
Material for the EPFL master course "A Network Tour of Data Science", edition 2019.
Stars: ✭ 62 (-26.19%)
Mutual labels:  graphs
StaticGraphs.jl
Memory-efficient immutable LightGraphs.
Stars: ✭ 33 (-60.71%)
Mutual labels:  graphs
graphite
Haskell graphs and networks library
Stars: ✭ 31 (-63.1%)
Mutual labels:  graphs
asciiframe
A CLI tool that converts videos to ASCII and displays them to the terminal on the fly
Stars: ✭ 20 (-76.19%)
Mutual labels:  ascii
WikiChron
Data visualization tool for wikis evolution
Stars: ✭ 19 (-77.38%)
Mutual labels:  graphs
hacktoberfest-data
Generating stats from the raw Hacktoberfest application data.
Stars: ✭ 21 (-75%)
Mutual labels:  graphs
Causing
Causing: CAUsal INterpretation using Graphs
Stars: ✭ 47 (-44.05%)
Mutual labels:  graphs
arcdiagram
R package arcdiagram
Stars: ✭ 75 (-10.71%)
Mutual labels:  graphs
ASCIIPlay
A simple video player that renders to ASCII written in C
Stars: ✭ 30 (-64.29%)
Mutual labels:  ascii
tt
Practicing touch typing, and monitor your typing speed using your own text files
Stars: ✭ 68 (-19.05%)
Mutual labels:  ascii

Sparklines

This Python package implements Edward Tufte's concept of sparklines, but limited to text only e.g. like this: ▃▁▄▁▅█▂▅ (this I likely not displayed correctly in every browser). You can find more information about sparklines on Wikipedia. This code was mainly developed for running simple plausibility tests in sensor networks as shown in fig. 1 below:

example usecase with sensor values

Fig. 1: Example usecase for such "sparklines" on the command-line, showing IoT sensor values (generating code not included here).

Due to limitations of available Unicode characters this works best when all values are positive. And even then true sparklines that look more like lines and less like bars are a real challenge, because they would need multiple characters with a single horizontal line on different vertical positions. This would work only with a dedicated font, which is way beyond the scope of this tool and which would significantly complicate its usage. So we stick to these characters: "▁▂▃▄▅▆▇█", and use a blank for missing values.

This code was tested ok at some point for Python 2.6 and 2.7, but no longer supports Python 2 after it reached end-of-life. Now Python 3.5 to 3.8 as well as PyPy 3 are all tested via Travis-CI.

Sample output

This is a recorded sample session illustrating how to use sparklines (as GitHub doesn't render embedded Asciinema recordings you'll see here an image pointing to the respective asciicast):

https://asciinema.org/a/5xwfvcrrk09fy3ml3a8n67hep.png

Here is some example output on the command-line (please note that in some browsers the vertical alignment of these block characters might be displayed slightly wrong, the same effect can be seen for other repos referenced below):

Examples for the code below:

$ sparklines 2 7 1 8 2 8 1 8
▂▇▁█▂█▁█
$ echo 2 7 1 8 2 8 1 8 | sparklines
▂▇▁█▂█▁█
$ sparklines < numbers.txt
▂▇▁█▂█▁█
$ sparklines 0 2. 1e0
▁█▅

Installation

You can install this package using pip install sparklines from the Python Package Index. You can also clone this repository and install it via python setup.py install or pip install -e .. After installing, you will have access system-wide (or in your virtualenv if you have used that) to sparklines, programmatically as well as via a command-line tool with the same name.

Test

To run the (still very small) "test suite", download and unpack this repository or clone it, and run the command python setup.py test in the unpacked archive. This will use a minified version of the pytest package included in this package in the file test/runtests.py. If you have the excellent pytest package installed you can also run py.test test from the downloaded repository's root folder.

Usage

Please note that the samples below might look a little funky (misaligned or even colored) in some browsers, but it should be totally fine when you print this in your terminal, Python or IPython session or your Python IDE of choice. Figure 2 below might show better what you should expect than the copied sample code thereafter:

example interactive invocation

Fig. 2: Example invocation from a Python and an IPython session.

Command-Line

Here are two sample invocations from the command-line, copied into this README:

$ sparklines 1 2 3 4 5.0 null 3 2 1
▁▃▅▆█ ▅▃▁

$ sparklines -n 2 1 2 3 4 5.0 null 3 2 1
  ▁▅█ ▁
▁▅███ █▅▁

Programmatic

And here are sample invocations from interactive Python sessions, copied into this README. The main function to use programmatically is sparklines.sparklines():

In [1]: from sparklines import sparklines

In [2]: for line in sparklines([1, 2, 3, 4, 5.0, None, 3, 2, 1]):
   ...:     print(line)
   ...:
▁▃▅▆█ ▅▃▁

In [3]: for line in sparklines([1, 2, 3, 4, 5.0, None, 3, 2, 1], num_lines=2):
    print(line)
   ...:
  ▁▅█ ▁
▁▅███ █▅▁

References

This code was inspired by Zach Holman's spark, converted to a Python module by Kenneth Reitz as spark.py and by RegKrieg to a Python package named pysparklines. And Roger Allen provides an even shorter spark.py.

But since it is so short and easy to code in Python we can add a few nice extra features I was missing, like:

  • increasing resolution with multiple output lines per sparkline
  • showing gaps in input numbers for missing data
  • issuing warnings for negative values (allowed, but misleading)
  • highlighting values exceeding some threshold with a different color (if termcolor package is available)
  • wrapping long sparklines at some max. length
  • (todo) adding separator characters like : at regular intervals
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].