gyli / PyWaffle

πŸ§‡ Make Waffle Charts in Python.
MIT License
578 stars 105 forks source link

characters argument and plt.savefig #17

Open SG-phimeca opened 4 years ago

SG-phimeca commented 4 years ago

There seem to be a problem when saving figures as pdf with matplotlib.pyplot.savefig and using the characters argument in Waffle: some characters are replaced by others.

list_character = ["πŸ–³", "🐍"]

from pywaffle import Waffle
from matplotlib import pyplot as plt

n_row = 4
n_column = 5

import numpy as np
list_value = np.ones(len(list_character))

fig = plt.figure(
    FigureClass=Waffle,
    rows=1,
    columns=len(list_character),
    values=list_value,
    characters=list_character,
    font_file="~/.fonts/Symbola.ttf",
    font_size=50
    )

plt.savefig("replaced_character.pdf")
plt.close("all")

yields the attached file (two snakes instead of a computer and a snake). The computer alone is correctly printed. Inverting the order yields two snakes.

replaced_character.pdf

gyli commented 4 years ago

Are you using the latest version, 0.4.1? I have tested the code above while I can't reproduce this issue.

Screen Shot 2019-10-28 at 10 27 11 AM
SG-phimeca commented 4 years ago

Yes, I use 0.4.1. Maybe some other package should be updated?!

gyli commented 4 years ago

Since I can't reproduce the issue, it's kind of tricky to figure out what goes wrong with your result. But it would be great if we can answer the following questions:

SG-phimeca commented 4 years ago
gyli commented 4 years ago

Interesting. If so, I’m thinking if it’s not the code or package related, but more related to the font or pdf reader. Since you are using a custom font, which might not be included or supported by something.

SG-phimeca commented 4 years ago

Installing pycairo and adding matplotlib.use('cairo') before plotting the figure solved the problem.

gyli commented 4 years ago

Good to know that works for you! It does remind me that I have cairo installed on my mac while I didn't switch matplotlib's backend manually.