Skip to content

Emoji Glyphs unrecognized in notebooks (nbAgg, tkAgg and WebAgg backends) #17498

Closed

Description

@python-villon

Bug report

Some glyphs of Emoji fonts (Segoe UI Emoji, NoTO Color Emopji or TwitterColor Emoji) are not rendered in nbAgg, tkAgg and WebAgg backends (Jupyter notebook).

But those fonts are well rendered with display(HTML( some_text) ).

I've been looking for all the issues related to this rendering problem but no solution solves the problem.

Code for reproduction

First thing I do is here : the settings of rcParams (I believe it's redundant but I wanted to be sure that everything leads to Segoe UI Emoji) and the font cache reset :

import matplotlib.font_manager as fm
from matplotlib import rcParams
from matplotlib.font_manager import findfont, FontProperties

## not written here : I erase the font cache file obtained via matplotlib.get_cachedir()

path = 'C:\\Windows\\Fonts\\seguiemj.ttf'
prop = fm.FontProperties(fname=path)
## print(prop.get_name())   --> Segoe UI Emoji
## print(prop.get_family()) --> ['sans-serif']

rcParams['font.family'] = 'sans-serif'
for family in ['sans-serif', 'serif', 'cursive', 'fantasy', 'monospace']:
    rcParams['font.' + family] = ['Segoe UI Emoji']
font = findfont(FontProperties(family=['sans-serif']))
font                # output display : 'C:\\Windows\\Fonts\\seguiemj.ttf'

Once it's done I do my plot :

# -*- coding: utf-8 -*-
%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib

#matplotlib.use('WebAgg', force=True)    ##also tested and gives the same error
#matplotlib.use('TkAgg', force=True)   ##also tested and leads to a crash

fig = plt.figure(figsize=(3, 3))
ax = fig.gca()  

t1 = ax.text(0.5, 1.5,'some_text_\U0001F600', fontproperties=prop)
t2 = ax.text(0.5, 0.5,'some_text_\u2639', fontproperties=prop)

plt.axis([0, 2, 0, 2])
plt.show()

this leads to the following Error message (when the font cache has been previously erased) :

- c:\users\surface\appdata\local\programs\python\python38\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 55357 missing from current font.
- font.set_text(s, 0.0, flags=flags)
- c:\users\surface\appdata\local\programs\python\python38\lib\site-packages\matplotlib\backends\backend_agg.py:214: RuntimeWarning: Glyph 56832 missing from current font.
- font.set_text(s, 0.0, flags=flags)
- c:\users\surface\appdata\local\programs\python\python38\lib\site-packages\matplotlib\backends\backend_agg.py:183: RuntimeWarning: Glyph 55357 missing from current font.
- font.set_text(s, 0, flags=flags)
- c:\users\surface\appdata\local\programs\python\python38\lib\site-packages\matplotlib\backends\backend_agg.py:183: RuntimeWarning: Glyph 56832 missing from current font.
- font.set_text(s, 0, flags=flags)

and the plot is :
capture1

However the font Segoe UI Emoji is the standard Windows Emoji Font (and I've also tried with Twitter Emoji font or NoTo Color Emoji) and it is usually compatible in Jupyter notebooks since the following code :

%%html
<style>
@font-face {
    font-family: 'Segoe UI Emoji';
    src: url(C:/Windows/Fonts/seguiemj.ttf) format("truetype");
}

.output{
  font-family: 'Segoe UI Emoji';
}
</style>

followed by :

from IPython.display import display, HTML

display(HTML('some_text_\U0001F600'))
display(HTML('some_text_\u2639'))

gives :
capture2

Since I've tried to solve the problem for a couple of a couple of hours with no solution, I post this here.
I hope you understand the problem I describe? I've watched many solutions but no one seems to work (I want to be on a standard installation in a GUI since this would be for educational purposes and I can't modify students machine settings or students machine installation, for instance using Cairo would not be relevant for me).

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.2.1
  • Matplotlib backend :
    - nbAgg : glyphs are never displayed on the plot (blank boxes) and en error is written on output when the font cache has been flushed.
    - WebAgg : glyphs are never displayed on the plot (blank boxes) and en error is written on output when the font cache has been flushed.
    - tkAgg : crash (infinite loop)
  • Python version: 3.8.2
  • Jupyter version (if applicable):
    - jupyter core : 4.6.3
    - jupyter-notebook : 6.0.3
    - qtconsole : 4.7.3
    - ipython : 7.13.0
    - ipykernel : 5.2.1
    - jupyter client : 6.1.3
    - jupyter lab : not installed
    - nbconvert : 5.6.1
    - ipywidgets : 7.5.1
    - nbformat : 5.0.6
    - traitlets : 4.3.3
  • matplotlib installed via pip, python via standrad installation

Activity

  1. anntzer commented on May 23, 2020

    @anntzer
    Contributor

    This actually works for me with (tk)agg (and Matplotlib master)... You get black and white emojis, but that's basically tracked at #12830.
    (The fact that display(HTML(...)) works is basically irrelevant for Matplotlib as the text rendering sytsem is completely different.)

  2. python-villon commented on May 23, 2020

    @python-villon
    Author

    Thanks for your reply.
    I am not sure to understand : are you meaning that the only known solution is to use mplCairo ?
    I had read #12830 and #4492 (that's why I mentionned Cairo in my last words) but I didn't want to use that solution.

    If it's the only way I will try it and keep you informed about the issue (Altough it doesn't fit to my needs for my students).

  3. anntzer commented on May 23, 2020

    @anntzer
    Contributor

    No, my point is that things actually work for me (with b/w) with (tk)agg.

  4. python-villon commented on May 23, 2020

    @python-villon
    Author

    Ok, so I've re-tried with TkAgg and it fails as with nbAgg or WebAgg.

    tkAgg_fenetre
    tkAgg_code

    I also try to do it with mplcairo but ... at the moment it crashes ... I further investigate mplcairo actuallly ...

  5. python-villon commented on May 23, 2020

    @python-villon
    Author

    I wonder why one Unicode code point is considered as two glyphs : it seems like if 32-bits unicode code points were considered as two glyphs (I'm not a unicode encoding specialist ... ???)

  6. python-villon commented on May 23, 2020

    @python-villon
    Author

    If you tell me that the support is only for black and white unicode code points, you can close the issue (typically if we should not use +U0001FXXX codepoints that lead to color glyphs).
    [I have done my best efforts to solve the issue]

  7. github-actions commented on Aug 4, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  8. tacaswell commented on Aug 4, 2023

    @tacaswell
    Member

    I am going to close this as:

    • emoji support is by font
    • supporting color fonts is a huge lift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions