CityofToronto / bdit_plotting_gallery

A gallery of static Python plots that the Big Data Innovation Team has produced
GNU General Public License v3.0
1 stars 0 forks source link

define font for plots #1

Open KatiRG opened 3 years ago

KatiRG commented 3 years ago

Using

class font:
    """
    Class defining the global font variables for all functions.
    """
    leg_font = font_manager.FontProperties(family='Libre Franklin',size=9)
    normal = 'Libre Franklin'
    semibold = 'Libre Franklin SemiBold'

mpl.rc('font',family='Libre Franklin')    

results in error: findfont: Font family ['Libre Franklin'] not found. Falling back to DejaVu Sans.

KatiRG commented 3 years ago

Very strange.

Plot font family and fonts can be defined using mpl.rcParams, see here.

e.g.

mpl.rcParams['font.family'] = 'sans-serif'

But, it seems that the above line needs to be run twice to actually work.....

So for now, this line is inside the function, but then before calling the function, I copy this line above the function call so that it runs again.

STRANGE!

KatiRG commented 3 years ago

About system fonts, you can find which fonts are already installed in your system in this file:

~/.cache/matplotlib/fontlist-v300.json

To install a new font:

Ask an admin to follow this tutorial.

IMPORTANT: Each user needs to remove their font cache (rm -r ~/.cache/matplotlib in the shell) and/or rebuild it with:

import matplotlib.font_manager as font_managerfont_manager._rebuild()