How to use unicode characters in matplotlib?

import matplotlib.pyplot as pyplot pyplot.figure() pyplot.xlabel(u"\u2736") pyplot.show() 

Here is the simplest code that I can create to show my problem. The axis mark symbol means a six-pointed star, but it appears as a box. How to change it to show a star? I tried adding a comment:

 #-*- coding: utf-8 -*- 

like the previous answers, but this did not work, as well as using matplotlib.rc or matplotlib.rcParams , which also did not work. Help will be appreciated.

+5
source share
1 answer

You will need a font with the specified Unicode character, STIX fonts must contain a star character. You will need to find or download STIX fonts, of course, any other ttf file with this symbol should be in order.

 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() 
+2
source

Source: https://habr.com/ru/post/1214856/


All Articles