3

I am new to matplotlib and trying to plot a 2D/3D chart with non-ASCII texts in it, I am able to use show() to plot on screen:

plt.text(X, Y, str(text[i].decode('utf-8')) )
plt.show()

However when I try to save the figure to a file with savefig(), all texts become little squares []

I am sure it is a font related problem but I can't see to figure out how to fix this.

I am on a Mac OSX 10.10.5, if that matters.

3
  • Probably a duplicate: stackoverflow.com/questions/10960463/… Commented Sep 23, 2015 at 10:21
  • Thanks, I googled that question but I try the suggested fonts without luck. Commented Sep 23, 2015 at 11:22
  • Yes, it depends very much on your unicode characters and the character map of the font. E.g. Arial won't have any glyphs for Chinese characters. Commented Sep 23, 2015 at 11:32

1 Answer 1

1

finally solved it by using:

fontpath = '/Library/Fonts/华文细黑.ttf'
properties = font_manager.FontProperties(fname=fontpath)
matplotlib.rcParams['font.family'] = properties.get_name()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.