matplotlib plugin for H2O Nitro
Project description
Matplotlib plugin for H2O Nitro
This plugin lets you use Matplotlib visualizations in Nitro apps.
Warning: Do not use pyplot! pyplot maintains references to the opened figures to make show() work, but this will cause memory leaks unless the figures are properly closed[1].
Demo
Install
pip install h2o-nitro-matplotlib
Usage
- Import
matplotlib_plugin
andmatplotlib_box
fromh2o_nitro_matplotlib
. - Add
matplotlib_plugin()
to your Nitro app. - Use
matplotlib_box(model)
to render Matplotlib models (figures, widgets, and so on).
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
[^1]: See Matplotlib docs on embedding .
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for h2o_nitro_matplotlib-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83a1b442eb4eaf5108ab92ae4d24dabdda35be96335fbfb70b41d2cc9800ebbc |
|
MD5 | 0de6bef219f16da4e32ae6a741c401de |
|
BLAKE2b-256 | 2b0d689aa9b87c1ce5be2f561607de7235801e76325ea3633921932cc5f49b89 |