我想使用一种可以显示所需所有表情符号的字体。我有一个如下所示的数据框:
chars num
0 😳 295
1 ☺ 365
2 😉 401
3 ♥ 426
4 😁 461
5 😄 488
6 🙈 499
7 😍 644
8 😊 691
9 ❤ 950
10 😂 1328
我想绘制表情符号的数量,而表情符号位于 xticks 中。我想在这里使用这种字体:Twemoji Color我已经安装了。我设法让它与标题、x_label、y_label 一起工作,但不能与 this solution 的 x_ticks 一起工作。 .
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
from matplotlib import ft2font
from matplotlib.font_manager import ttfFontProperty
import pandas as pd
fpath = '/usr/share/fonts/Twitter Color Emoji/TwitterColorEmoji-SVGinOT.ttf'
fprop = fm.FontProperties(fname=fpath)
font = ft2font.FT2Font(fpath)
fprop = fm.FontProperties(fname=fpath)
ttfFontProp = ttfFontProperty(font)
fontprop = fm.FontProperties(family='sans-serif',
fname=ttfFontProp.fname,
size=fontsize,
stretch=ttfFontProp.stretch,
style=ttfFontProp.style,
variant=ttfFontProp.variant,
weight=ttfFontProp.weight)
emojis = ['😳', '☺', '😉', '♥', '😁', '😄', '🙈', '😍', '😊', '❤', '😂']
nums = [295, 365, 401, 426, 461, 488, 499, 644, 691, 950, 1328]
df = pd.DataFrame({'chars': emojis, 'num': nums})
axis = df.plot.bar()
axis.set_title(' '.join(emojis), fontproperties=prop)
axis.set_xticklabels(df.chars.tolist(), rotation=0, fontsize=5)
plot.show()
目前我正在执行以下操作:
import matplotlib.pyplot as plt
import pandas as pd
emojis = ['😳', '☺', '😉', '♥', '😁', '😄', '🙈', '😍', '😊', '❤', '😂']
nums = [295, 365, 401, 426, 461, 488, 499, 644, 691, 950, 1328]
df = pd.DataFrame({'chars': emojis, 'num': nums})
axis = x.plot.bar()
plt.show()
我现在知道我可以使用axis.set_xticklabels(df.chars.tolist(), rotation=0)
让表情符号向右旋转,但不知道如何正确设置字体。
最佳答案
您链接的 Twemoji Color 页面上显示“目前只有 FireFox 支持 SVGinOT 颜色表情符号”。
您最好使用另一个渲染为 html 的绘图库并使用 FireFox 来查看它。
关于python - matplotlibs xticks 中的表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51989729/