0
votes

In a part of a project, I need to depict some symbols. However, a few of symbols are not showing/saving properly.

import matplotlib.pyplot as plt
%matplotlib inline

plt.subplots(1,1, facecolor='w', dpi = 150)

plt.text(0.1, 0.9, ['This is a test', "⭘" , '◔'])
plt.text(0.1, 0.8, ['This is a test', "⭘" , '◔'], fontname = 'Arial')
plt.text(0.1, 0.7, ['This is a test', "⭘" , '◔'], fontname = 'SimHei')

plt.yticks([0,0.5,1],["⭘",'◔','⏺'])

plt.savefig('unicode_error.png')
plt.show()

The result is as follows, where the plot does not show some symbols: plot does not show some symbols

I am running in Win10, I tried both back-ends: nbAgg and backend_inline.

Two main questions:
1. How to solve the main problem of showing "⭘" or "⏺" ?
2. How to change default font to a font that is not included in matplotlib.font_manager (in my case "SimHei")? Currently, I am receiving the following warning: C:\Users\mabag\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\font_manager.py:1328: UserWarning: findfont: Font family ['SimHei'] not found. Falling back to DejaVu Sans (prop.get_family(), self.defaultFamily[fontext]))

2

2 Answers

0
votes

The Font in use needs to actually provide the unicode symbol. Here you may want to use

plt.text(0.1, 0.9, ['This is a test', "○" , '◔'])

or

plt.text(0.1, 0.8, ['This is a test', "◯" , '◔'])

enter image description here

0
votes

After spending many hours, I found the solution:

from matplotlib import rcParams
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Segoe UI Symbol','simHei','Arial','sans-serif']

However, the most important point was to delete chached .matplotlib folder. Te folder is usually in c:\users\your_username\.matplotlib (in Windows) or home\.matplotlib (in Linux).