Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emojis are not displayed in bar chart #6

Open
trislee opened this issue May 6, 2022 · 0 comments
Open

Emojis are not displayed in bar chart #6

trislee opened this issue May 6, 2022 · 0 comments

Comments

@trislee
Copy link
Contributor

trislee commented May 6, 2022

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.
image18

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant