Background
MatPlotLib is a fantastic graphic package. But when I sometimes need to plot dataset in Chinese. I have found some problem.
There are two methods for representing non-English font with MatPlotLib.
Method 1
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # YaHei is one common Chinese font
mpl.rcParams['axes.unicode_minus'] = False # Repair the bug of representing '-'as "square"
Wiht this method, all the text and number showing in the figure are all in the Chinese Font.
Method 2
Differently, I predefine the pathway of the some chinese font and call it when I need to use.
from matplotlib.font_manager import FontProperties
chinese = FontProperties(fname=r'/Library/Fonts/Microsoft/SimHei.ttf', size=20)
ax = plt.gca()
ax.set_title(u'能量随时间的变化', fontproperties=chinese)
My Problem
When a string contains Chinese text and English text together (e.g, Chinese as the variable, and it should come with some units: kg, m/s.)
质量 == Mass
as.set_xlabel(u'质量' + '(kg)') ==> Want to define their font sepearetly.
So, I want the string can be mixed up with Chinese and English font together as an unit?
Is it possible to achieve that?