Issue
import matplotlib.pyplot as pyplot
pyplot.figure()
pyplot.xlabel(u"\u2736")
pyplot.show()
Here is the simplest code I can create to show my problem. The axis label symbol is meant to be a six-pointed star but it shows as a box. How do I change it so the star is shown? I've tried adding the comment:
#-*- coding: utf-8 -*-
like previous answers suggested but it didn't work, as well as using matplotlib.rc
or matplotlib.rcParams
which also didn't work. Help would be appreciated.
Solution
You'll need a font that has the given unicode character, STIX fonts should contain the star symbol. You'll need to locate or download the STIX fonts, ofcourse any other ttf file with the given symbol should be fine.
import matplotlib.pyplot as pyplot
from matplotlib.font_manager import FontProperties
if __name__ == "__main__":
pyplot.figure()
prop = FontProperties()
prop.set_file('STIXGeneral.ttf')
pyplot.xlabel(u"\u2736", fontproperties=prop)
pyplot.show()
Answered By - arjenve
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.