Skip to main content

Easy font management for matplotlib

Project description

mpl_fontkit

pypi

  • Use font from google fonts
  • Set the font and use it easily
  • Helpful error message to get your font name right

Install

pip install mpl_fontkit

Quick Start

from mpl_fontkit import FontKit

# https://fonts.google.com/specimen/Lato?query=Lato
fk = FontKit().get("Lato")

If the font does not available in matplotlib, this will download from Google and add it to matplotlib.

To check available styles for a font

fk.font_table("Lato")
  Name     Style    Variant    Weight   Stretch 
  ----     -----    -------    -----    ------- 
  Lato     normal    normal     250      normal 
  Lato     italic    normal     250      normal 
  Lato     normal    normal     300      normal 
  Lato     italic    normal     300      normal 
  Lato     normal    normal     400      normal 
  Lato     italic    normal     400      normal 
  Lato     normal    normal     700      normal 
  Lato     italic    normal     700      normal 
  Lato     normal    normal     900      normal 
  Lato     italic    normal     900      normal 

And then you are ready to use it in your plots

import matplotlib.pyplot as plt
_, ax = plt.subplots()
ax.set_title("Lato Font", fontdict={"style": "italic", 
                                    "weight": 700, 
                                    "size": 24})
show in plot

To set a font manually. This will update the rcParams for you.

from mpl_fontkit import FontKit
FontKit().set_global("Lato")

Most of the time when you can't get the font to work simply because the font name is not the same as the file name. You can just type a fuzzy name, we will try to find a similar name and show you in the error message.

from mpl_fontkit import FontKit
FontKit().set_global("Lat")
LookupError: Cannot find Lat, do you mean: Lato. Use `.fonts()` to list all the available fonts.

Get available fonts

from mpl_fontkit import FontKit
print(FontKit().fonts())
['Agency FB',
 'Algerian',
 'Arial',
 'Arial Rounded MT Bold',
 'Bahnschrift',
 'Baskerville Old Face',
 'Bauhaus 93',
 ...]

To show what a font looks like

from mpl_fontkit import FontKit
FontKit().show("Lato")
# To display all fonts at once
# FontKit().show_fonts()

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

mpl_fontkit-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

mpl_fontkit-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mpl_fontkit-0.1.0.tar.gz.

File metadata

  • Download URL: mpl_fontkit-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for mpl_fontkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 28027eeda430786a697919f16eee3c3af4cb4583410086bb4ec607fd0cfa7320
MD5 8ec9f97473e3a6d8708868b5c740202e
BLAKE2b-256 b4ee34d7646dbfbffc17cc166bf225a1fa78e24ed13dc2edc074eeb5f8c33a10

See more details on using hashes here.

Provenance

File details

Details for the file mpl_fontkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpl_fontkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for mpl_fontkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53028a7f5af35240c1f0ab529edabcc421019fbf725a2c073787b185df1c7c66
MD5 1c5345ba1604c8d1b2f7f1c82a02afbf
BLAKE2b-256 5bbb681acefbcc2be8ad74c3576daab16fcea73006bf8adf80b2923b1f1cea2e

See more details on using hashes here.

Provenance

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