Skip to main content

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()). 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:

from IPython.display import Markdown
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:
Markdown(f'![My beautiful figure]({mh.img(plt)}){{#fig:1}}')

Qt backend gives interactive plots in Atom/Hydrogen.

Hints

  1. Delete fontList.cache, fontList.py3k.cache or fontList.json from %USERPROFILE%\.matplotlib folder after installing a new font.
  2. 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()
  1. 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

matplotlibhelper-0.0.6.tar.gz (2.8 MB view details)

Uploaded Source

File details

Details for the file matplotlibhelper-0.0.6.tar.gz.

File metadata

  • Download URL: matplotlibhelper-0.0.6.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for matplotlibhelper-0.0.6.tar.gz
Algorithm Hash digest
SHA256 7b6215e0085895c23d4929dc4fd8054639eb8a6830bb6ec2ac596506d043fd94
MD5 6906686636df241fecfe1c28fb900fb1
BLAKE2b-256 d82cab3474cd23da4b3096e4061f375dc0e6837e56cd7540ea491492c879bdaf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page