Matplotlib Helper is my custom helper to tune Matplotlib experience in Atom/Hydrogen and Pandoctools/Knitty.
Project description
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'![My beautiful figure]({mh.img()}){{#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.cache
orfontList.json
from%USERPROFILE%\.matplotlib
folder 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file matplotlibhelper-0.0.9.tar.gz
.
File metadata
- Download URL: matplotlibhelper-0.0.9.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f748987e7a2a3805965cb6a234c30018e42b7056a5a356e754ae3bcd22bba7b4 |
|
MD5 | 53d26daac3d43602826d10c3e3566cac |
|
BLAKE2b-256 | 467848a44ad8dc6c9664fb7cf61e74851d2fbdb5298c73016e1eebabe947adb2 |