0

I'm trying to create a table figure in png.

The data in the table contains non-ascii characters.(suppose it's chinese or something)

I pass unicode code-points (u'hello') to pyplot and it shows the characters as squares.

1
  • 1
    What context? As labels, as text, otherwise? Also: what Python version (2 or 3) may be relevant here. Last: show us your code Commented Oct 21, 2013 at 9:54

2 Answers 2

1

It may be (slightly) platform dependent, but I prefer to use unicode for Chinese and other languages. One other thing is that you need to make sure is matplotlib must get the necessary font. You can do it anywhere you need a text except sometimes not with mathtext.

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import matplotlib
zhfont1 = matplotlib.font_manager.FontProperties(fname='/Library/Fonts/Kai.dfont') #I am on OSX.
s=u'\u54c8\u54c8' #Need the unicode for your Chinese Char.
plt.text(0.5,0.5,s,fontproperties=zhfont1, size=50) #example: plt.text()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

another method is to modify the file /matplotlibrc/ on your matplotlib system.

Find this line

#font.sans-serif

and add your font in this line.

And then you need to add the font-file into the font directory of matplotlib.

Here I give this two paths:

  1. ~\AppData\Local\Enthought\Canopy\User\Lib\site-packages\matplotlib\mpl-data
  2. $HOME.matplotlib\fontList.cache

PS: Windows 7.

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.