You problem here is that the default font have no good support for emojis.
In plt.annotate
function, you can add a parameter fontname
to specify the typeface that has a good support for emojis.
Following code are what I got on my Windows machine with some edits to your code, it seems that "Segoe UI Emoji" has been installed on my computer already.
# this line is for jupyter notebook
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
# config the figure for bigger and higher resolution
plt.rcParams["figure.figsize"] = [12.0, 8.0]
plt.rcParams['figure.dpi'] = 300
data = np.random.randn(7, 2)
plt.scatter(data[:, 0], data[:, 1])
labels = '?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??'.split()
print(labels)
for label, x, y in zip(labels, data[:, 0], data[:, 1]):
plt.annotate(
label, # some of these contain Emojis
xy=(x, y), xytext=(-20, 20),
textcoords='offset points', ha='right', va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0'),
fontname='Segoe UI Emoji', # this is the param added
fontsize=20)
plt.show()
Here is what I got, the emojis may not show clearly, it depends on your typeface:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…