Skip to content

Emoji missing when use plt.savefig() #4492

Closed

Description

@yeqingyan

I am trying to use matplotlib draw frequency of emoji used in text. Emoji looks good when I called plt.show() to show the figure.
emoji_good

But after I call plt.savefig("test.png") to save figures, the emojis were missing.
emoji_missing

Is there any way to show emoji in png files? Thank you!

My system is Mac OS X Yosemite 10.10.3, my matplotlib version is 1.3.1.

Activity

  1. WeatherGod commented on Jun 2, 2015

    @WeatherGod
    Member

    Which backend are you using? I suspect the OS is supplying the emoji images
    through the GUI framework, so it wouldn't work in all backends, nor have we
    ever written tests for this. I doubt it would be trivial to add support for
    it throughout mpl.
    On Jun 2, 2015 4:04 PM, "yeqingyan" [email protected] wrote:

    I am trying to use matplotlib draw frequency of emoji used in text. Emoji
    looks good when I called plt.show() to show the figure.
    [image: emoji_good]
    https://cloud.githubusercontent.com/assets/8574101/7945703/4fcef0a2-0927-11e5-8810-f98a8e658e3c.png

    But after I call plt.savefig("test.png") to save figures, the emojis were
    missing.
    [image: emoji_missing]
    https://cloud.githubusercontent.com/assets/8574101/7945725/72ff83c0-0927-11e5-92aa-e477c8d3a1cf.png

    Is there any way to show emoji in png files? Thank you!

    My system is Mac OS X Yosemite 10.10.3, my matplotlib version is 1.3.1.

    —
    Reply to this email directly or view it on GitHub
    #4492.

  2. yeqingyan commented on Jun 2, 2015

    @yeqingyan
    Author

    I think the backend I used is MacOSX. I got it by running following commands:

    import matplotlib
    matplotlib.get_backend()
    'MacOSX'

  3. tacaswell commented on Jun 3, 2015

    @tacaswell
    Member

    @WeatherGod emoji are just unicode, support only depneds on the font being use. The issue here is that the font being used by osx is a system font which has them and for the png I bet it is falling back to the fonts we ship. Explicitly setting the text to use a font that has the emoji glyphs should be all that is needed.

  4. mdboom commented on Jun 3, 2015

    @mdboom
    Member

    Wow. Talk about something cool that works completely by accident!

  5. WeatherGod commented on Jun 3, 2015

    @WeatherGod
    Member

    I wonder if resetting the font list cache might help here? I don't know how
    well the font-finding mechanisms work on macs, but it should pick up the
    system font, no?

    On Wed, Jun 3, 2015 at 8:44 AM, Michael Droettboom <[email protected]

    wrote:

    Wow. Talk about something cool that works completely by accident!

    —
    Reply to this email directly or view it on GitHub
    #4492 (comment)
    .

  6. yeqingyan commented on Jun 3, 2015

    @yeqingyan
    Author

    Thank you for your reply! I followed font example here http://matplotlib.org/examples/pylab_examples/fonts_demo.html, I tried to set the emoji font family,but I still got the same result, the emoji looks good after call show function, but they are missing after I save it to png files.

    from matplotlib.font_manager import FontProperties
    from pylab import *
    
    subplot(111, axisbg='w')
    
    font0 = FontProperties()
    alignment = {'horizontalalignment':'center', 'verticalalignment':'baseline'}
    ###  Show family options
    
    family = ['Apple Color Emoji', 'Apple Color Emoji', 'Apple Color Emoji', 'Apple Color Emoji', 'Apple Color Emoji']
    
    font1 = font0.copy()
    font1.set_size('large')
    
    t = text(-0.8, 0.9, 'family', fontproperties=font1,
             **alignment)
    
    yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]
    
    for k in range(5):
        font = font0.copy()
        font.set_family(family[k])
        if k == 2:
            font.set_name('Script MT')
        #print emoji
        t = text(-0.8, yp[k], '\xf0\x9f\x98\x8d'.decode("utf-8"), fontproperties=font,
                 **alignment)
    axis([-1,1,0,1])
    show()
    

    In show window:
    screen shot 2015-06-03 at 2 37 40 pm
    After save it to png file:
    figure_1

  7. tacaswell commented on Jun 19, 2015

    @tacaswell
    Member

    I think you want to be setting the font name, not family, ex

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    t = ax.text(.5, .5, b'\xF0\x9F\x98\x85\xf0\x9f\x98\x8d\xF0\x9F\x98\x85'.decode('utf-8'), fontname='symbola', fontsize=30, ha='center')
    t = ax.text(.5, .25, '😅😍😅', fontname='symbola', fontsize=30, ha='center')

    so

    from matplotlib.figure_manager import fontManager as fm
    
    fm.findfont(prop)
    

    will let you run the font search and will tell you (via a warning) if it fails.

  8. pelson commented on Jun 22, 2015

    @pelson
    Member

    @tacaswell - I hope you've lined this example up for the state of the library talk! 😄

  9. tacaswell commented on Jun 22, 2015

    @tacaswell
    Member

    The plan is emoji + hello in a collection of languages.

  10. WeatherGod commented on Jun 22, 2015

    @WeatherGod
    Member

    Do we still not support right-to-left fonts such as arabic and hebrew?

    On Mon, Jun 22, 2015 at 1:34 PM, Thomas A Caswell [email protected]
    wrote:

    The plan is emoji + hello in a collection of languages.

    —
    Reply to this email directly or view it on GitHub
    #4492 (comment)
    .

  11. tacaswell commented on Jun 22, 2015

    @tacaswell
    Member

    Ah, I bet we do not.

    On Mon, Jun 22, 2015 at 1:45 PM Benjamin Root [email protected]
    wrote:

    Do we still not support right-to-left fonts such as arabic and hebrew?

    On Mon, Jun 22, 2015 at 1:34 PM, Thomas A Caswell <
    [email protected]>
    wrote:

    The plan is emoji + hello in a collection of languages.

    —
    Reply to this email directly or view it on GitHub
    <
    #4492 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    #4492 (comment)
    .

  12. mdboom commented on Jun 22, 2015

    @mdboom
    Member

    Yeah -- the text layout algorithm is still "Naive American [TM]"

    On Mon, Jun 22, 2015 at 1:47 PM Thomas A Caswell [email protected]
    wrote:

    Ah, I bet we do not.

    On Mon, Jun 22, 2015 at 1:45 PM Benjamin Root [email protected]
    wrote:

    Do we still not support right-to-left fonts such as arabic and hebrew?

    On Mon, Jun 22, 2015 at 1:34 PM, Thomas A Caswell <
    [email protected]>
    wrote:

    The plan is emoji + hello in a collection of languages.

    —
    Reply to this email directly or view it on GitHub
    <

    #4492 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    <
    #4492 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    #4492 (comment)
    .

  13. samsaara commented on Jun 28, 2016

    @samsaara

    I tried @tacaswell's suggestions but with Apple Emoji.

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    t = ax.text(.5, .25, '😅😍😅', fontname='Apple Color Emoji', fontsize=30, ha='center')
    

    plt.show() displays nicely:

    screen shot 2016-06-28 at 12 05 05 pm

    But I couldn't save it and instead get the same boxes as shown above in the thread. I could save with Symbola font though. So is there any way I can take advantage of Apple Emoji while saving ?

    I use Mac OS X 10.11.5 and Matplotlib 1.5.1

  14. WeatherGod commented on Jun 28, 2016

    @WeatherGod
    Member

    This is probably related to the differences in the macosx's font lookup
    which enables it to find more fonts than what matplotlib can find. Have you
    tried clearing your font-cache?

    On Tue, Jun 28, 2016 at 6:38 AM, Keviv [email protected] wrote:

    I tried @tacaswell https://github.com/tacaswell's suggestions but with Apple
    Emoji.

    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()
    t = ax.text(.5, .25, '😅😍😅', fontname='Apple Color Emoji', fontsize=30, ha='center')

    plt.show() displays nicely:

    [image: screen shot 2016-06-28 at 12 05 05 pm]
    https://cloud.githubusercontent.com/assets/6368653/16412435/777411d4-3d2c-11e6-9b5a-d7175ed99ce3.jpg

    But I couldn't save it and instead get the same boxes as shown above in
    the thread. I could save with Symbola font though. So is there any way I
    can take advantage of Apple Emoji while saving ? Like copying the font to
    somewhere inside matplotlib folder ?

    I use Mac OS X 10.11.5 and Matplotlib 1.5.1

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #4492 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AARy-MhgxdygejugiZqckRmshxdWHqdoks5qQPm9gaJpZM4E1MPk
    .

  15. samsaara commented on Jun 28, 2016

    @samsaara

    if you mean, deleting the .matplotlib folder, then yes; I've tried that option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions