Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

characters argument and plt.savefig #17

Open
SG-phimeca opened this issue Oct 28, 2019 · 7 comments
Open

characters argument and plt.savefig #17

SG-phimeca opened this issue Oct 28, 2019 · 7 comments

Comments

@SG-phimeca
Copy link

SG-phimeca commented Oct 28, 2019

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
Copy link
Owner

gyli commented Oct 28, 2019

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
Copy link
Author

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

@gyli
Copy link
Owner

gyli commented Oct 29, 2019

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:

  • Does it only happen to pdf files, or is it the same result when showing in a pop window or save with other image format?
  • Could you check fig._pa to make sure it is the right parameters being passed?
  • Could you please find a shareable notebook, such as Azure Notebooks, which can also produce the same result, so that I can take a look and maybe start debugging?

@SG-phimeca
Copy link
Author

  • yes, it only happens when saving to pdf. Not in interactive mode, nor when saving to scg or png.
  • The value associated to 'characters' in fig._pa is correct.
  • It might take some time. I'll try.

@gyli
Copy link
Owner

gyli commented Oct 29, 2019

Interesting. If so, I鈥檓 thinking if it鈥檚 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
Copy link
Author

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

@gyli
Copy link
Owner

gyli commented Oct 29, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants