Skip to main content

Simple python api to visualize the plots in a script.

Project description

[![Documentation Status](https://readthedocs.org/projects/local-visualizer/badge/?version=latest)](http://local-visualizer.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://travis-ci.org/psvishnu91/local_visualizer.svg?branch=master)](https://travis-ci.org/psvishnu91/local_visualizer)
[![PyPI version](https://badge.fury.io/py/local-visualizer.svg)](https://badge.fury.io/py/local-visualizer)

## LocalVisualizer

Simple python api to visualize the plots in a script.

* Free software: MIT license
* Documentation: https://local-visualizer.readthedocs.io
* PyPI: https://pypi.python.org/pypi/local-visualizer/

### Installation
``` bash
pip install local-visualizer
```

### Motivation
* When moving from an IPython notebook to a script, we lose the diagnostics
of visualizing pandas as tables and matplotlib plots.
* :class:`LocalViz` starts a local http server and creates a html file to
which pandas tables and matplotlib plots can be sent over.
* The html file is dynamically updated for long running scripts.

### Usage
``` python
import logging, sys, numpy as np, pandas as pd, matplotlib.pyplot as plt
import local_visualizer

plt.style.use('fivethirtyeight')
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

# Create the local visualizer instance
lviz = local_visualizer.LocalViz(html_file='lviz_test.html', port=9112)
# INFO:root:Starting background server at: http://localhost:9112/.
# INFO:local_visualizer:Click: http://carpediem:9112/lviz_test.html or http://localhost:9112/lviz_test.html

# Create plots which will be streamed to the html file.
lviz.h3('Matplotlib :o')
lviz.p(
'Wrap your plots in the figure context manager which takes '
'in the kwargs of plt.figure and returns a plt.figure object.',
)

with lviz.figure(figsize=(10, 8)) as fig:
x = np.linspace(-10, 10, 1000)
plt.plot(x, np.sin(x))
plt.title('Sine test')

lviz.hr()

# Visualize pandas dataframes as tables.
lviz.h3('Pandas dataframes')

df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat(
[df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
axis=1,
)
lviz.write(df)
lviz.close()
```

### Output
This starts a HTTPServer and creates a html file which is dynamically updated
each time ``lviz`` is called.

![Output image]( https://i.imgur.com/jjwvAX2.png "The output of the above commands")

### Support and Requirements
Python 2.7

### API methods
1. `p`: paragraph
2. `br`: line break
3. `hr`: Horizontal rule with line breaks
4. `h1`, `h2`, ..., `h6`: Headers
5. `write`: Directly write text to the html document (or pass in a `pandas.DataFrame`)
6. `figure`: Context manager which accepts the kwargs of `plt.figure` and returns a `plt.figure` object
7. `start`: Applicable if `LocalViz` was initialized with `lazy=True`. Starts the server and creates the html file
8. `close`: Completes the html file
9. `del_html`: Deletes the html file

### Credits
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

0.2.0 (2017-11-06)
------------------

The close method no more deletes the html but only makes the html valid.

0.1.0 (2017-11-05)
------------------

* First release on PyPI.


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

local_visualizer-0.2.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

local_visualizer-0.2.0-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file local_visualizer-0.2.0.tar.gz.

File metadata

File hashes

Hashes for local_visualizer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4b68a4c7ff392835c3cd87c2100fc31a91861ab0f5263668d2988d8d13863937
MD5 e68a790c70de8b231e881ace89d51aa6
BLAKE2b-256 b6e50df09c3732f5f02a045eb818a6071b1f4e5f7afb196819c1fef21fbc95ff

See more details on using hashes here.

File details

Details for the file local_visualizer-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for local_visualizer-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b7d49b6040ed710a57d947e93c92356802d22456aa92c3d5468d597b9f509536
MD5 c6a98a089e383736d4009c8e295dc126
BLAKE2b-256 2c53ee6d22ed18ed7f2deccbb0bc3595dc260ab023196063db399b7d5b7f6001

See more details on using hashes here.

Supported by

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