sparklines


Namesparklines JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/deeplook/sparklines
SummaryGenerate sparklines for numbers using Unicode characters only.
upload_time2024-04-27 09:24:03
maintainerNone
docs_urlNone
authorDinu Gherman
requires_pythonNone
licenseGPL
keywords visualization chart tool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Sparklines
==========

.. image:: https://img.shields.io/github/actions/workflow/status/deeplook/sparklines/python-package.yml
  :target: https://pypi.org/project/sparklines

.. image:: https://img.shields.io/pypi/pyversions/sparklines.svg
  :target: https://pypi.org/project/sparklines
  
.. image:: https://img.shields.io/pypi/v/sparklines.svg
  :target: https://pypi.org/project/sparklines/

.. image:: https://static.pepy.tech/badge/sparklines/month
  :target: https://pepy.tech/project/sparklines

.. image:: https://img.shields.io/pypi/status/sparklines.svg
  :target: https://pypi.org/project/sparklines

.. image:: https://img.shields.io/pypi/format/sparklines.svg
  :target: https://pypi.org/project/sparklines

.. image:: https://img.shields.io/pypi/l/sparklines.svg
  :target: https://pypi.org/project/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:

.. figure:: https://raw.githubusercontent.com/deeplook/sparklines/main/example_sensors.png
   :width: 75%
   :alt: example usecase with sensor values
   :align: center

   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>`_):

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

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:

.. code-block:: bash

    $ 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 test suite, download and unpack this repository or clone it,
run `pip inastall pytest`, and run the command ``pytest tests`` in the
unpacked archive. 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:

.. figure:: https://raw.githubusercontent.com/deeplook/sparklines/main/example_python.png
   :width: 65%
   :alt: example interactive invocation
   :align: center

   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:

.. code-block:: console

    $ 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()``:

.. code-block:: python

    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 
<https://github.com/holman/spark>`_, converted to a Python module 
by Kenneth Reitz as `spark.py 
<https://raw.githubusercontent.com/kennethreitz/spark.py/master/spark.py>`_ 
and by RegKrieg to a Python package named `pysparklines <https://github.com/RedKrieg/pysparklines>`_.
And Roger Allen provides an even `shorter spark.py 
<https://gist.githubusercontent.com/rogerallen/1368454/raw/b17e96b56ae881621a9f3b1508ca2e7fde3ec93e/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

.. _Asciinema: https://asciinema.org
.. _Python Package Index: https://pypi.python.org/pypi/sparklines/
.. _sparklines: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR
.. _on Wikipedia: https://en.wikipedia.org/wiki/Sparkline

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deeplook/sparklines",
    "name": "sparklines",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "visualization, chart, tool",
    "author": "Dinu Gherman",
    "author_email": "gherman@darwin.in-berlin.de",
    "download_url": "https://files.pythonhosted.org/packages/42/10/a55ffb7b5ae130804ebcb53ecbb711a902403fe7efe67739aceeb4daf8f5/sparklines-0.5.0.tar.gz",
    "platform": null,
    "description": "Sparklines\n==========\n\n.. image:: https://img.shields.io/github/actions/workflow/status/deeplook/sparklines/python-package.yml\n  :target: https://pypi.org/project/sparklines\n\n.. image:: https://img.shields.io/pypi/pyversions/sparklines.svg\n  :target: https://pypi.org/project/sparklines\n  \n.. image:: https://img.shields.io/pypi/v/sparklines.svg\n  :target: https://pypi.org/project/sparklines/\n\n.. image:: https://static.pepy.tech/badge/sparklines/month\n  :target: https://pepy.tech/project/sparklines\n\n.. image:: https://img.shields.io/pypi/status/sparklines.svg\n  :target: https://pypi.org/project/sparklines\n\n.. image:: https://img.shields.io/pypi/format/sparklines.svg\n  :target: https://pypi.org/project/sparklines\n\n.. image:: https://img.shields.io/pypi/l/sparklines.svg\n  :target: https://pypi.org/project/sparklines\n  \nThis Python package implements Edward Tufte's concept of sparklines_, but\nlimited to text only e.g. like this: \u2583\u2581\u2584\u2581\u2585\u2588\u2582\u2585 (this I likely not displayed\ncorrectly in every browser). You can find more information about sparklines\n`on Wikipedia`_. This code was mainly developed for running simple\nplausibility tests in sensor networks as shown in fig. 1 below:\n\n.. figure:: https://raw.githubusercontent.com/deeplook/sparklines/main/example_sensors.png\n   :width: 75%\n   :alt: example usecase with sensor values\n   :align: center\n\n   Fig. 1: Example usecase for such \"sparklines\" on the command-line,\n   showing IoT sensor values (generating code not included here).\n\nDue to limitations of available Unicode characters this works best when all\nvalues are positive. And even then true sparklines that look more like lines\nand less like bars are a real challenge, because they would need multiple\ncharacters with a single horizontal line on different vertical positions. This\nwould work only with a dedicated font, which is way beyond the scope of this\ntool and which would significantly complicate its usage. So we stick to these\ncharacters: \"\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\", and use a blank for missing values.\n\nThis code was tested ok at some point for Python 2.6 and 2.7, but no longer\nsupports Python 2 after it reached end-of-life. Now Python 3.5 to 3.8 as well\nas PyPy 3 are all tested via Travis-CI.\n\n\nSample output\n-------------\n\nThis is a recorded sample session illustrating how to use ``sparklines`` (as\nGitHub doesn't render embedded Asciinema_ recordings you'll see here an image\npointing to the respective\n`asciicast <https://asciinema.org/a/5xwfvcrrk09fy3ml3a8n67hep>`_):\n\n.. image:: https://asciinema.org/a/5xwfvcrrk09fy3ml3a8n67hep.png\n   :target: https://asciinema.org/a/5xwfvcrrk09fy3ml3a8n67hep\n\nHere is some example output on the command-line (please note that in some\nbrowsers the vertical alignment of these block characters might be displayed\nslightly wrong, the same effect can be seen for other repos referenced below):\n\nExamples for the code below:\n\n.. code-block:: bash\n\n    $ sparklines 2 7 1 8 2 8 1 8\n    \u2582\u2587\u2581\u2588\u2582\u2588\u2581\u2588\n    $ echo 2 7 1 8 2 8 1 8 | sparklines\n    \u2582\u2587\u2581\u2588\u2582\u2588\u2581\u2588\n    $ sparklines < numbers.txt\n    \u2582\u2587\u2581\u2588\u2582\u2588\u2581\u2588\n    $ sparklines 0 2. 1e0\n    \u2581\u2588\u2585\n\n\nInstallation\n------------\n\nYou can install this package using ``pip install sparklines`` from the `Python\nPackage Index`_.\nYou can also clone this repository and install it via ``python setup.py install``\nor ``pip install -e .``.\nAfter installing, you will have access system-wide (or in your virtualenv\nif you have used that) to ``sparklines``, programmatically as well as via a\ncommand-line tool with the same name.\n\nTest\n----\n\nTo run the test suite, download and unpack this repository or clone it,\nrun `pip inastall pytest`, and run the command ``pytest tests`` in the\nunpacked archive. from the downloaded repository's root folder.\n\n\nUsage\n-----\n\nPlease note that the samples below might look a little funky (misaligned or \neven colored) in some browsers, but it should be totally fine when you print\nthis in your terminal, Python or IPython session or your Python IDE of choice.\nFigure 2 below might show better what you should expect than the copied sample\ncode thereafter:\n\n.. figure:: https://raw.githubusercontent.com/deeplook/sparklines/main/example_python.png\n   :width: 65%\n   :alt: example interactive invocation\n   :align: center\n\n   Fig. 2: Example invocation from a Python and an IPython session.\n\n\nCommand-Line\n............\n\nHere are two sample invocations from the command-line, copied into this README:\n\n.. code-block:: console\n\n    $ sparklines 1 2 3 4 5.0 null 3 2 1\n    \u2581\u2583\u2585\u2586\u2588 \u2585\u2583\u2581\n\n    $ sparklines -n 2 1 2 3 4 5.0 null 3 2 1\n      \u2581\u2585\u2588 \u2581  \n    \u2581\u2585\u2588\u2588\u2588 \u2588\u2585\u2581\n\n\nProgrammatic\n............\n\nAnd here are sample invocations from interactive Python sessions, copied into\nthis README. The main function to use programmatically is \n``sparklines.sparklines()``:\n\n.. code-block:: python\n\n    In [1]: from sparklines import sparklines\n\n    In [2]: for line in sparklines([1, 2, 3, 4, 5.0, None, 3, 2, 1]):\n       ...:     print(line)\n       ...:     \n    \u2581\u2583\u2585\u2586\u2588 \u2585\u2583\u2581\n\n    In [3]: for line in sparklines([1, 2, 3, 4, 5.0, None, 3, 2, 1], num_lines=2):\n        print(line)\n       ...:     \n      \u2581\u2585\u2588 \u2581  \n    \u2581\u2585\u2588\u2588\u2588 \u2588\u2585\u2581\n\n\nReferences\n----------\n\nThis code was inspired by Zach Holman's `spark \n<https://github.com/holman/spark>`_, converted to a Python module \nby Kenneth Reitz as `spark.py \n<https://raw.githubusercontent.com/kennethreitz/spark.py/master/spark.py>`_ \nand by RegKrieg to a Python package named `pysparklines <https://github.com/RedKrieg/pysparklines>`_.\nAnd Roger Allen provides an even `shorter spark.py \n<https://gist.githubusercontent.com/rogerallen/1368454/raw/b17e96b56ae881621a9f3b1508ca2e7fde3ec93e/spark.py>`_.\n\nBut since it is so short and easy to code in Python we can add a few nice\nextra features I was missing, like:\n\n- increasing resolution with multiple output lines per sparkline\n- showing gaps in input numbers for missing data\n- issuing warnings for negative values (allowed, but misleading)\n- highlighting values exceeding some threshold with a different\n  color (if ``termcolor`` package is available)\n- wrapping long sparklines at some max. length\n- (todo) adding separator characters like ``:`` at regular intervals\n\n.. _Asciinema: https://asciinema.org\n.. _Python Package Index: https://pypi.python.org/pypi/sparklines/\n.. _sparklines: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR\n.. _on Wikipedia: https://en.wikipedia.org/wiki/Sparkline\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Generate sparklines for numbers using Unicode characters only.",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/deeplook/sparklines"
    },
    "split_keywords": [
        "visualization",
        " chart",
        " tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9daa58f65cdf8117ae679ee4ddb3ab502d6ded7be2616d13cb179151e045b94",
                "md5": "b19322b5793e84da9ae5b8a8ab4c2ced",
                "sha256": "436861df6382a5cf663ea9e0a52dcb5d4f95f5111f8e01eb637eca529e3f6807"
            },
            "downloads": -1,
            "filename": "sparklines-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b19322b5793e84da9ae5b8a8ab4c2ced",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 23110,
            "upload_time": "2024-04-27T09:23:23",
            "upload_time_iso_8601": "2024-04-27T09:23:23.532914Z",
            "url": "https://files.pythonhosted.org/packages/e9/da/a58f65cdf8117ae679ee4ddb3ab502d6ded7be2616d13cb179151e045b94/sparklines-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4210a55ffb7b5ae130804ebcb53ecbb711a902403fe7efe67739aceeb4daf8f5",
                "md5": "1f5ce00c2c9ff57d38ce5f4a856f5441",
                "sha256": "069e48633fc1af354e9bbdfd0a644c1279d6632a572446aa9d741105f1177000"
            },
            "downloads": -1,
            "filename": "sparklines-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1f5ce00c2c9ff57d38ce5f4a856f5441",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25005,
            "upload_time": "2024-04-27T09:24:03",
            "upload_time_iso_8601": "2024-04-27T09:24:03.611474Z",
            "url": "https://files.pythonhosted.org/packages/42/10/a55ffb7b5ae130804ebcb53ecbb711a902403fe7efe67739aceeb4daf8f5/sparklines-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 09:24:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deeplook",
    "github_project": "sparklines",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sparklines"
}
        
Elapsed time: 0.24177s