GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot render Apple Color Emoji in plots · Issue #12830 · matplotlib/matplotlib

Cannot render Apple Color Emoji in plots #12830

New issue
Copy link
New issue
Copy link
Open
Open
Cannot render Apple Color Emoji in plots#12830
Copy link
Assignees
QuLogic
Labels
keepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actiontopic: text/fonts
Milestone
v3.12.0

Description

@brienna
brienna
opened on Nov 18, 2018
Issue body actions

Bug report

In both Jupyter Notebook and Terminal, I cannot display emojis using the Apple Color Emoji font.

If I attempt to set fontname='Apple Color Emoji' matplotlib won't find the font, and falls back to the default font DejaVu Sans, which renders the image below.

download 2

If I try to load the font using font_manager.FontProperties, it throws an error: RuntimeError: In FT2Font: Could not set the fontsize.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import numpy as np

prop = FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')

freqs = [301, 96, 53, 81, 42]
labels = ['😊', '😱', '😂', '😄', '😛']
plt.figure(figsize=(12,8))
p1 = plt.bar(np.arange(len(labels)), freqs, 0.8, color="lightblue")
new_ylim = plt.ylim()[1]+30
plt.ylim(0, new_ylim)

# Make labels
for rect1, label in zip(p1, labels):
    height = rect1.get_height()
    plt.annotate(
        label,
        (rect1.get_x() + rect1.get_width()/2, height+5),
        ha="center",
        va="bottom",
        #fontsize='30',
        #fontname='Apple Color Emoji'
        fontproperties = prop
    )
    
plt.show()

Matplotlib version

  • Operating system: MacOS Sierra 10.12.6
  • Matplotlib version: 2.2.3
  • Matplotlib backend: MacOSX and module://ipykernel.pylab.backend_inline
  • Python version: Python 3.7.0
  • Jupyter version (if applicable): 5.6.0

Related StackOverflow question.

Reacted by Samuel Ainsworth and Toma

Activity

Next
  1. ImportanceOfBeingErnest commented on Nov 18, 2018

    @ImportanceOfBeingErnest
    ImportanceOfBeingErnest
    on Nov 18, 2018
    Member
    More actions

    Similar problem: #4492

    It seems this somehow worked by coincidence. But as commented on the SO post already, one would start by using the codes that are reported to work in #4492 and see where the difference is.

  2. ImportanceOfBeingErnest
    added
    Community supportUsers in need of help.Users in need of help.
    on Nov 18, 2018
  3. anntzer commented on Nov 18, 2018

    @anntzer
    anntzer
    on Nov 18, 2018
    Contributor
    More actions

    Actually that's a limitation of FT2Font.
    I couldn't get my hands on Apple Color Emoji.ttc, but at least with Apple Color Emoji.ttf, things work if you use the mplcairo backend (https://github.com/anntzer/mplcairo), and I have no reason to believe that the ttc version would be different.

    (The fact that setting the fontname instead of the path doesn't work for ttc files "should" be fixed by #9787, which "just" waits for a second review...)

    Reacted by Brienna Herold and Ruben Vereecken
    Reacted by Anya Bataeva
  4. anntzer
    added
    topic: text
    and removed
    Community supportUsers in need of help.Users in need of help.
    on Nov 18, 2018
  5. brienna commented on Nov 18, 2018

    @brienna
    brienna
    on Nov 18, 2018
    Author
    More actions

    According to #3135, ttc font support is limited as well. It would be nice if we have #9787...

    @anntzer, I can't seem to build the wheels with mplcairo, using OS X.

  6. anntzer commented on Nov 18, 2018

    @anntzer
    anntzer
    on Nov 18, 2018
    Contributor
    More actions

    There are some instructions at https://github.com/anntzer/mplcairo#building. Can you let me know what specific issues you are having with the build?

  7. brienna commented on Nov 19, 2018

    @brienna
    brienna
    on Nov 19, 2018
    Author
    More actions

    When running clang build-osx-wheel.sh:

    ld: warning: ignoring file build-osx-wheel.sh, file was built for unsupported file format ( 0x23 0x21 0x2F 0x62 0x69 0x6E 0x2F 0x62 0x61 0x73 0x68 0x0A 0x0A 0x23 0x20 0x42 ) which is not the architecture being linked (x86_64): build-osx-wheel.sh
    Undefined symbols for architecture x86_64:
      "_main", referenced from:
         implicit entry/start for main executable
    ld: symbol(s) not found for architecture x86_64
    clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
    
  8. anntzer commented on Nov 19, 2018

    @anntzer
    anntzer
    on Nov 19, 2018
    Contributor
    More actions

    You don't want to run clang build-osx-wheel.sh, but just ./build-osx-wheel.sh (or even python setup.py bdist_wheel should be good enough (modulo dependencies) given that you just want to use the wheel locally).

  9. brienna commented on Nov 19, 2018

    @brienna
    brienna
    on Nov 19, 2018
    Author
    More actions

    Thanks! The installation got a bit further this time, but ends with

    src/_feature_tests.cpp:3:4: error: "A compiler supporting C++17 is required."
      #error "A compiler supporting C++17 is required."
       ^
    1 error generated.
    error: command 'x86_64-apple-darwin13.4.0-clang' failed with exit status 1
    

    I had installed clang via homebrew llvm as instructed in the Build section.

  10. anntzer commented on Nov 19, 2018

    @anntzer
    anntzer
    on Nov 19, 2018
    Contributor
    More actions

    Well, that's what the error message says: your version of clang is too old. You can install a more recent version with homebrew or conda, then make sure it is active.

  11. brienna commented on Nov 19, 2018

    @brienna
    brienna
    on Nov 19, 2018
    Author
    More actions

    Two things were important: To git clone the repo instead of downloading it, and to make sure that llvm's compiler variables were set correctly before installing:

    echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
    source ~/.bash_profile
    export LDFLAGS="-L/usr/local/opt/llvm/lib"
    export CPPFLAGS="-I/usr/local/opt/llvm/include"
    export CC='/usr/local/opt/llvm/bin/clang'
    export CXX='/usr/local/opt/llvm/bin/clang++'
    tools/build-osx-wheel.sh
    

    I moved build > lib.macosx-10.9-x86_64-3.7 > mplcairo to my repo where I had my code, and in Jupyter Notebook added:

    import mplcairo
    matplotlib.use("module://mplcairo.macosx")
    print(matplotlib.get_backend())
    

    Τhen I ran my code again and got

    screen shot 2018-11-18 at 11 27 57 pm

    So much better! But monochrome? 😩😤 And other colors are off too.

  12. anntzer commented on Nov 19, 2018

    @anntzer
    anntzer
    on Nov 19, 2018
    Contributor
    More actions

    Not sure what's happening with monochrome but...

    1. You need to install the wheel (that's in the dist directory) with pip install /path/to/mplcairo-etc-etc.whl.
    2. Making things work in the notebook is a bit hackish (does it work better if you run a standalone script outside of the notebook?), however (having installed the wheel as above) things should work in the notebook if you set the MPLCAIRO_PATCH_AGG environment variable to 1 before starting the jupyter server (e.g. MPLCAIRO_PATCH_AGG=1 jupyter notebook), as documented in https://github.com/anntzer/mplcairo#use.

    Also, can you check your version of cairo? (mplcairo._mplcairo.__cairo_version__) It needs to be at least 1.15.8 for color emoji support (https://www.phoronix.com/scan.php?page=news_item&px=Cairo-1.15.8-Colored-Emoji). And let's also get the freetype version (mplcairo._mplcairo.__freetype_version__) while we're at it.

  13. brienna commented on Nov 19, 2018

    @brienna
    brienna
    on Nov 19, 2018
    Author
    More actions

    Installed the wheel so I can import mplcairo systemwide.

    Ran a standalone script outside the notebook by importing mplcairo (owing to your MPLCAIRO_PATCH_AGG and MacOSX backend incompatibility notes), as well as running in Jupyter using MPLCAIRO_PATCH_AGG=1 jupyter notebook. Both approaches yield the same monochromatic emojis.

    I'm using cairo 1.18.0.

  14. anntzer commented on Nov 19, 2018

    @anntzer
    anntzer
    on Nov 19, 2018
    Contributor
    More actions

    I'm using cairo 1.18.0.

    That's the pycairo version (I know, it's confusing :/).
    The cairo version is accessible as import mplcairo._mplcairo; print(mplcairo._mplcairo.__cairo_version__); can you check that, and the freetype version too (as above)?
    Also, perhaps try some other color emoji font, e.g. Noto Color Emoji (https://github.com/googlei18n/noto-emoji/tree/master/fonts)?

    Still not sure why it's failing for you...

  15. 36 remaining items

  16. github-actions
    added
    status: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Action
    on Nov 8, 2024
  17. anntzer commented on Nov 8, 2024

    @anntzer
    anntzer
    on Nov 8, 2024
    Contributor
    More actions

    Still a valid request.

    Reacted by Whitney
  18. story645
    added
    keepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Action
    on Nov 8, 2024
  19. QuLogic
    self-assigned this
    on Feb 27, 2025
  20. QuLogic commented on Feb 27, 2025

    @QuLogic
    QuLogic
    on Feb 27, 2025
    Member
    More actions

    I'm going to try and see if I can get this in with the font shaping work.

    Reacted by Antony Lee
  21. anntzer commented on Feb 27, 2025

    @anntzer
    anntzer
    on Feb 27, 2025
    Contributor
    More actions

    @QuLogic I saw you mentioned in this week's meeting notes that raqm is working "except font fallback". This is very exciting :-)
    Regarding font fallback, it looks like the "proper" approach (as described by the author of raqm...) is the one described at https://tex.stackexchange.com/questions/520034/fallback-for-harfbuzz-fonts#comment1315285_520048, which I have tried to implement for mplcairo (raqm's API should be enough to implement it, by relying on raqm_set_freetype_face_range) but is actually a bit tedious to do...

  22. QuLogic commented on Feb 27, 2025

    @QuLogic
    QuLogic
    on Feb 27, 2025
    Member
    More actions

    Yep, that is in fact what I'm following (I think you had the link in mplcairo), but running into some issues with it not actually doing it. I think there may be some cache interfering, so I'm going to try to layout from scratch for every fallback, but that is as you say a bit tedious.

  23. QuLogic
    added this to the v3.11.0 milestone on Jun 5, 2025
  24. QuLogic
    added this to Font and text overhaulon Jun 5, 2025
  25. github-project-automation
    moved this to Waiting for other PR in Font and text overhaulon Jun 5, 2025
  26. QuLogic commented on Jun 12, 2025

    @QuLogic
    QuLogic
    on Jun 12, 2025
    Member
    More actions

    With the FT2Image removal and FreeType 2.13, I am able to render some colour emoji:

    Image

    This is only COLRv0, and I believe some modern fonts are using SVG instead. I also discovered some bugs in the FreeType API we're using, so there may need to be some additional workarounds/patches in place. That will require a bit more work, but will probably happen after all the other stuff is merged.

    Reacted by Antony Lee
  27. anntzer commented on Jun 12, 2025

    @anntzer
    anntzer
    on Jun 12, 2025
    Contributor
    More actions

    I'd be curious to hear about the bugs (even if very summarily). Also, support for SVG fonts looks awkward as freetype requires you to bring your own SVG(-subset) renderer; from a quick look I just realized that cairo, for example, implements its own. Do you have a plan here?

  28. QuLogic
    modified the milestones: v3.11.0, v3.12.0 on May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @QuLogic
    QuLogic

Labels

keepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actiontopic: text/fonts

Type

No type

Projects

  • Font and text overhaul
    Status
    Waiting for other PR
    Show more project fields

Milestone

  • v3.12.0No due date

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.