8000 Emoji missing when use plt.savefig() · Issue #4492 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Emoji missing when use plt.savefig() #4492

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

Closed
yeqingyan opened this issue Jun 2, 2015 · 15 comments
Closed

Emoji missing when use plt.savefig() #4492

yeqingyan opened this issue Jun 2, 2015 · 15 comments

Comments

@yeqingyan
Copy link

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.

@WeatherGod
Copy link
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" notifications@github.com 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.

@yeqingyan
Copy link
Author

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

import matplotlib
matplotlib.get_backend()
'MacOSX'

@tacaswell
Copy link
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.

@mdboom
Copy link
Member
mdboom commented Jun 3, 2015

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

@WeatherGod
Copy link
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 <notifications@github.com

wrote:

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


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

@yeqingyan
Copy link
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

@tacaswell
Copy link
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.

@pelson
Copy link
Member
pelson commented Jun 22, 2015

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

@tacaswell
Copy link
Member

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

8000

@WeatherGod
Copy link
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 notifications@github.com
wrote:

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


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

@tacaswell
Copy link
Member

Ah, I bet we do not.

On Mon, Jun 22, 2015 at 1:45 PM Benjamin Root notifications@github.com
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 <
notifications@github.com>
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)
.

@mdboom
Copy link
Member
mdboom commented Jun 22, 2015

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

On Mon, Jun 22, 2015 at 1:47 PM Thomas A Caswell notifications@github.com
wrote:

Ah, I bet we do not.

On Mon, Jun 22, 2015 at 1:45 PM Benjamin Root notifications@github.com
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 <
notifications@github.com>
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)
.

@samsaara
Copy link
samsaara commented Jun 28, 2016

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

@WeatherGod
Copy link
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 notifications@github.com 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
.

@samsaara
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
0