1

I am trying to use PyWaffle (https://github.com/ligyxy/PyWaffle) to plot waffle charts.

I have installed the module and I have installed the fontawesome fonts (https://fontawesome.com/?from=io) that are used by PyWaffle.

I then run the following code provided in the Git repo.

data = {'Democratic': 48, 'Republican': 46, 'Libertarian': 3}
fig = plt.figure(
    FigureClass=Waffle, 
    rows=5, 
    values=data, 
    colors=("#232066", "#983D3D", "#DCB732"),
    legend={'loc': 'upper left', 'bbox_to_anchor': (1, 1)},
    icons='child', icon_size=18, 
    icon_legend=True
)

This should return the following plot: enter image description here

Instead I get the following exception.

FileNotFoundError: [Errno 2] No such file or directory: 'font/FontAwesome.otf'

The steps I used to install the FontAwesome were the ones listed in their website:

  1. First I downloaded the zipped folder
  2. Next, I unzipped the folder enter image description here
  3. Then I opened it enter image description here enter image description here

I right-clicked on the fonts and selected: Install.

halfer
  • 19,824
  • 17
  • 99
  • 186
user8270077
  • 4,621
  • 17
  • 75
  • 140

1 Answers1

3

PyWaffle seems to look for the font files in a location relative to the calling script (or python interpreter / jupyter notebook), rather than in the installed system fonts. The error is thrown because it can't find it.

The font file is installed as part of the PyWaffle package, it just doesn't look in the right place. You can work around this by finding the font directory in your virtual environment's or system's site-packages directory, and copying it to the same location as your script.

Alternatively you can edit the file waffle.py, found in the pywaffle directory of your site-packages to replace this line:

FONTAWESOME_FILE = 'font/FontAwesome.otf'

With these:

import os
import font
FONTAWESOME_FILE = os.path.join(font.__path__[0], 'FontAwesome.otf')

It's a bit of a kludge and would be overwritten when you upgrade the package, but it would allow any scripts you write to make use of icons without having to copy the font file each time.

EDIT

This has now been fixed, so upgrading the package to the latest version should be enough.

mostlyoxygen
  • 981
  • 5
  • 14