Code Monkey home page Code Monkey logo

mpl-fontkit's Introduction

mpl_fontkit

pypi

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

Install

pip install mpl_fontkit

Quick Start

Install Google Fonts

import mpl_fontkit as fk

# https://fonts.google.com/specimen/Lato?query=Lato
fk.install("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")

And then you are ready to use it in your plots

import matplotlib.pyplot as plt
plt.text("Lato Font", fontdict={"style": "italic", "weight": 700, "size": 24})

show in plot

Install Font Awesome

To install font awesome and use it in your plot.

fk.install_fontawesome()

plt.text(.5, .5, "\uf58b\uf005\uf59b", fontfamily="Font Awesome 6 Free")

The font awesome is available as Font Awesome 6 Free and Font Awesome 6 Brands, the name of icon is encoded as unicode.

You can search for icons and get the unicode here.

fontawesome showcase

Set a font globally

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

import mpl_fontkit as fk

fk.set_font("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.

import mpl_fontkit as fk

fk.set_font("Lat")
LookupError: Cannot find Lat, do you mean: Lato. 
    Use `.list_fonts()` to list all the available fonts.

Get available fonts

fk.list_fonts()
['Agency FB',
 'Algerian',
 'Arial',
 'Arial Rounded MT Bold',
 'Bahnschrift',
 'Baskerville Old Face',
 'Bauhaus 93',
 ...]
 

What fonts look like?

Show one font

fk.show("Lato")

Show all fonts at once

fk.show_fonts()

mpl-fontkit's People

Contributors

mr-milk avatar

Stargazers

 avatar

Watchers

 avatar

mpl-fontkit's Issues

A final destination for the font file

The user_data_path may not always work, an extra fail safe should be added.

We should create a hidden folder called .font at the current directory when it's impossible to write to other places.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.