Metadata-Version: 2.1
Name: h2o-nitro-matplotlib
Version: 0.2.1
Summary: matplotlib plugin for H2O Nitro
Home-page: https://github.com/h2oai/nitro-matplotlib
Author: Prithvi Prabhu
Author-email: prithvi.prabhu@gmail.com
License: UNKNOWN
Project-URL: Documentation, https://github.com/h2oai/nitro-matplotlib
Project-URL: Source, https://github.com/h2oai/nitro-matplotlib
Project-URL: Issues, https://github.com/h2oai/nitro-matplotlib/issues
Platform: UNKNOWN
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Widget Sets
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: h2o-nitro (>=0.9.2)
Requires-Dist: matplotlib

# Matplotlib plugin for H2O Nitro

This plugin lets you use [Matplotlib](https://matplotlib.org/stable/index.html)
and [Seaborn](https://seaborn.pydata.org/) visualizations in [Nitro](https://github.com/h2oai/nitro) apps.

**Warning: Try to avoid pyplot in web apps!** pyplot maintains references to the opened figures to make show() work, but
this will cause memory leaks unless the figures are properly closed[^1].

[^1]: See [Matplotlib docs on embedding](https://matplotlib.org/3.5.0/gallery/user_interfaces/web_application_server_sgskip.html)

## Demo

[View source](example).

![Matplotlib](demo_matplotlib.gif)

![Seaborn](demo_seaborn.gif)

## Install

```
pip install h2o-nitro-matplotlib
```

## Usage

1. Import `matplotlib_plugin` and `matplotlib_box` from `h2o_nitro_matplotlib`.
2. Add `matplotlib_plugin()` to your Nitro app.
3. Use `matplotlib_box(figure)` to render Matplotlib figures, or `matplotlib_box()` (without arguments) to render the
   current global `matplotlib.pyplot`.

.

```py 
from matplotlib.figure import Figure
from h2o_nitro import View, web_directory
from h2o_nitro_matplotlib import matplotlib_plugin, matplotlib_box


def main(view: View):
    view(matplotlib_box(make_plot()))


nitro = View(
    main,
    title='Nitro + Matplotlib',
    caption='A minimal example',
    plugins=[matplotlib_plugin()],  # Include the Matplotlib plugin
)

def make_plot():
    x = np.linspace(0, 2, 100)  # Sample data.

    # Important: Generate the figure **without using pyplot**.
    fig = Figure()

    ax = fig.subplots()
    ax.plot(x, x, label='linear')  # Plot some data on the axes.
    ax.plot(x, x ** 2, label='quadratic')  # Plot more data on the axes...
    ax.plot(x, x ** 3, label='cubic')  # ... and some more.
    ax.set_xlabel('x label')  # Add an x-label to the axes.
    ax.set_ylabel('y label')  # Add a y-label to the axes.
    ax.legend()  # Add a legend.

    return fig

```




