
LocalVisualizer
Simple python api to visualize the plots in a script.
Installation
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
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)
lviz = local_visualizer.LocalViz(html_file='lviz_test.html', port=9112)
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()
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.

Support and Requirements
Python 2.7
API methods
p
: paragraph
br
: line break
hr
: Horizontal rule with line breaks
h1
, h2
, ..., h6
: Headers
write
: Directly write text to the html document (or pass in a pandas.DataFrame
)
figure
: Context manager which accepts the kwargs of plt.figure
and returns a plt.figure
object
start
: Applicable if LocalViz
was initialized with lazy=True
. Starts the server and creates the html file
close
: Completes the html file
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)