fh-matplotlib
Making it easier to show matplotlib charts in FastHTML.
Usage
You can install this tool by running:
python -m pip install fh-matplotlib
After this step, it is ready for use! At the moment this package merely contains a decorator. You can use it to wrap any function that generates a matplotlib chart in order for it to return an Img for FastHTML to render. In, short you would typically use it like this:
import numpy as np
import matplotlib.pylab as plt
from fh_matplotlib import matplotlib2fasthtml
# This function will return a proper Img that can be rendered
@matplotlib2fasthtml
def matplotlib_function():
plt.plot(np.arange(25), np.random.exponential(1, size=25))
Want to see a full example that you could copy and paste directly?
from fh_matplotlib import matplotlib2fasthtml
from fasthtml.common import *
import numpy as np
import matplotlib.pylab as plt
app, rt = fast_app()
count = 0
plotdata = []
@matplotlib2fasthtml
def generate_chart():
global plotdata
plt.plot(range(len(plotdata)), plotdata)
@app.get("/")
def home():
return Title("Matplotlib Demo"), Main(
H1("Matplotlib Demo"),
P("Nothing too fancy, but still kind of fancy."),
Div(f"You have pressed the button {count} times.", id="chart"),
Button("Increment", hx_get="/increment", hx_target="#chart", hx_swap="innerHTML"),
style="margin: 20px"
)
@app.get("/increment/")
def increment():
global plotdata, count
count += 1
plotdata.append(np.random.exponential(1))
return Div(
generate_chart(),
P(f"You have pressed the button {count} times."),
)
serve()
Roadmap
This repository is originally meant to be simple helper, but if there are more advanced use-cases to consider I will gladly consider them. Please start a conversation by opening up an issue before starting a PR though.
Metadata
Release files for fh-matplotlib 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fh-matplotlib-0.0.4.tar.gz | 3.7 kB | Without provenance | Details for fh-matplotlib-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fh_matplotlib-0.0.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for fh_matplotlib-0.0.4-py2.py3-none-any.whl |
Total release size: 8.7 kB
Release files / fh-matplotlib-0.0.4.tar.gz
| Download URL | fh-matplotlib-0.0.4.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55c47c94ae5705decf01ba71cfc3fd55b5f1af2382410d08c8fc2fc2a37b560b
|
|
BLAKE2b-256 checksum How to use checksums |
427e5643d69ab4a6eaa7d0ce7121f180ced64fc1cc87e2d76587b5aacfc7b0db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Release files / fh_matplotlib-0.0.4-py2.py3-none-any.whl
| Download URL | fh_matplotlib-0.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
61922185ddd36b0273675bb453bece3d6d73ebf621c907083d157bf487556d11
|
|
BLAKE2b-256 checksum How to use checksums |
4c4c87034946a9b868ee0fe92c19082064eb10bcb268923efa0159dfb2a726ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Security for fh-matplotlib 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.