Matplotlib Helper
Matplotlib Helper is my custom helper to tune Matplotlib experience for Pandoctools/Knitty (but it can be used by itself). I tuned fonts (that are shipped with this python package), please see default fonts and other options in default keyword arguments of ready(...), img(...) and img_path(...). I made some tweaks to use it with SugarTeX, some tweaks to automatically use interactive Qt5 plots in Atom/Hydrogen or non-jupyter Python. It can also export plots to SVG or PNG.
Works in Jupyter as well.
Contents
Install
Via conda:
conda install -c defaults -c conda-forge matplotlibhelper
Via pip:
pip install matplotlibhelper
Additionally you may need to install to use in Jupyter Lab:
conda install jupyterlab jupyterlab_server tk nodejs
pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
Instead of pip install ipympl you can also try:
conda update --all
conda install -c defaults -c conda-forge ipympl
conda update --all
Usage example
Usage example that works both in Atom+Hydrogen and in Pandoctools+Knitty:
import IPython.display as ds
import matplotlibhelper as mh
mh.ready(font_size=14) # should be run before import matplotlib.pyplot
import matplotlib.pyplot as plt
plt.figure(figsize=mh.figsize(w=6)) # height is automatic via the golden ration
plt.plot([1, 2, 3, 4])
plt.ylabel(mh.stex('ˎ∇ ⋅ [ ⃗E]ˎ, V/m')) # using SugarTeX
# this code in Knitty would be parsed by Pandoc,
# in Atom/Hydrogen or Jupyter it would be displayed:
ds.display(ds.Markdown(
f'}){{#fig:1}}'
))
# or if you have image size issues in Hydrogen try:
ds.display(ds.HTML(
f'<img src="{mh.img()}" width="900">'
))
Qt backend gives interactive plots in Atom/Hydrogen.
Hints
- Delete
fontList.cache,fontList.py3k.cacheorfontList.jsonfrom%USERPROFILE%\.matplotlibfolder after installing a new font. - If font becomes bold without a reason try (source):
from matplotlib import font_manager
if 'roman' in font_manager.weight_dict:
del font_manager.weight_dict['roman']
# noinspection PyProtectedMember
font_manager._rebuild()
- Install Computer Modern Unicode for bold-italic unicode support:
"mathtext.sf": "CMU Serif:bold:italic". Sans-serif command\mathsf{}is reassigned because sans-serif font is rarely used in serif docs.
Metadata
Release files for matplotlibhelper 0.0.10
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 | |
|---|---|---|---|---|
| matplotlibhelper-0.0.10.tar.gz | 1.7 MB | Without provenance | Details |
Release files / matplotlibhelper-0.0.10.tar.gz
| Download URL | matplotlibhelper-0.0.10.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5801ee817d1bc8be97fbe2e44c6f326b153b47c315d5304fd93bf9d867d06e1
|
|
BLAKE2b-256 checksum How to use checksums |
ce97c44f732b5c10ef33432eabec720afc3f47949f2c799aee0848f142f3e3c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1.post20191125 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5
|
Security for matplotlibhelper 0.0.10
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.