tiktok-hashtag-analysis
tiktok-hashtag-analysis copied to clipboard
Emojis are not displayed in bar chart
For hashtags containing emojis (such as #ukraine🇺🇦), the plot generated by hashtag_frequencies.plot does not display the emoji, as shown in the figure below.

The problem seems to be that the default matplotlib font can't handle non-ASCII characters. One option would be using a different font, but I doubt there's any single font installed by default on all operating systems (Windows, macOS, Linux) that we could specify. One way around this is to specify a font for each operating system, e.g.
from sys import platform
...
if platform == 'win32':
font_path = <WINDOWS SYSTEM FONT THAT SUPPORTS EMOJIS>.otf
elif platform == 'darwin':
font_path = <MACOS SYSTEM FONT THAT SUPPORTS EMOJIS>.otf
elif platform in ('linux', 'linux2'):
font_path = <LINUX/UBUNTU SYSTEM FONT THAT SUPPORTS EMOJIS>.otf
else:
USE DEFAULT FONT
font_manager.fontManager.addfont(font_path)
prop = font_manager.FontProperties(fname=font_path)
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = prop.get_name()
Another option could be using a package like mplcairo.
see the following links for reference:
- https://stackoverflow.com/a/8220141
- https://stackoverflow.com/a/69016300
- https://github.com/matplotlib/matplotlib/issues/12830