I have an exotic task for Matplpoltlib for which I need to display emoji inside labels. I am using OS X, so there is a good system-wide support of emoji. However, things do not work out with Matplotlib: currently, emoji get displayed as empty boxes. I am using Python 3, so Unicode should not be a problem. Thank you
Asked
Active
Viewed 2,076 times
2
-
You have to tell mpl to use a font which has the emojii, the default one does not. – tacaswell May 05 '15 at 15:50
-
`prop = fm.FontProperties(fname='/System/Library/Fonts/Apple\ Color\ Emoji.ttf')` `matplotlib.rcParams['font.family'] = prop.get_name()` Results in "Could not set the fontsize for facefile" – Alealeale May 05 '15 at 17:11
-
1Possible duplicate of [Substitute node labels with emoji using networkX in Python](http://stackoverflow.com/questions/33190985/substitute-node-labels-with-emoji-using-networkx-in-python) – Abdallah Sobehy Oct 20 '15 at 00:37
1 Answers
5
The idea behind it is not very difficult but in order to get it to be displayed (at least on ubunto) it gave me some hard time as not all fonts support emoji. I shall display the straight forward way but for some of the steps I had to make are detailed here in case you encounter any difficulties.
From emoji cheat sheet from the emoji python package I picked up three to be shown as an example and here is the code.
G = nx.Graph()
G.add_nodes_from([0,1,2])
n0 = emoji.emojize(':thumbsup:',use_aliases=True)
n1 = emoji.emojize(':sob:',use_aliases=True)
n2 = emoji.emojize(':joy:',use_aliases=True)
labels ={0:n0,1:n1,2:n2}
nx.draw_networkx(G,labels=labels, node_color = 'w', linewidths=0, with_labels=True, font_family = 'Symbola' ,font_size = 35)
plt.show()

Community
- 1
- 1

Abdallah Sobehy
- 2,881
- 1
- 15
- 28
-
If this question is a duplicate of the linked question (aka if the same answer can apply to both questions), then please flag this question as a duplicate instead of leaving an answer to that effect. If it is not a duplicate, please leave a complete answer instead of a link-only answer. – josliber Oct 19 '15 at 00:50
-
1That was my first thought (I am not still an expert with how to deal with situations on SOF). But the thing is this question was asked before the question I answered, so at that time there was no answer. So, my hunch was it would mean that the asked did not make enough effort to find an existing solution which was not there. – Abdallah Sobehy Oct 19 '15 at 00:56
-
But I guess copying the complete answer here is not the best reaction also. This means I should flag it as a duplicate right ? – Abdallah Sobehy Oct 19 '15 at 00:57
-
It is OK to flag an older question as a duplicate of a newer one if the newer one has better answers. Since that seems to be the case here, that sounds like the best course of action. – josliber Oct 19 '15 at 00:57
-
So now there is another issue, I have just posted my answer so when I tried to flag as a duplicate it said that this question does not have an up-voted or accepted answer. So, shall I paste the answer here then duplicate later if it is accepted ? – Abdallah Sobehy Oct 19 '15 at 01:05
-
Okay I have made the change for the answer referencing the other one with more details. Is it okay that way ? @josilber – Abdallah Sobehy Oct 19 '15 at 01:28
-
I have to say it is kind of discouraging when I spend a lot of time to answer a question and when I find a similar one during my research for a solution I care to return to leave the answer or link to it and I get a negative vote. – Abdallah Sobehy Oct 19 '15 at 18:37
-
@user3666197 that definitely turned tables around for me, Thanks for the nice words. I think being a bit new to SOF I am enthusiastic about giving a good answer to the domain I know about, spending time, insisting to answer questions even if I have never encountered such problems. That is why the fireback after such effort has an effect on me I admit. But I will bare it in mind from now on. – Abdallah Sobehy Oct 20 '15 at 14:37
-
I have started to read the blog, but I think I am scared that it will put me off a bit. So, I think I will postpone it for later and continue with my attitude and then maybe read it later, when I get cooler about SOF. – Abdallah Sobehy Oct 20 '15 at 14:42
-
1Michael **links a few genuine [Answers] of his choice, that are pretty delightfull on their own**. Take a joy on 'em. There was no intention to interpret his observations, but to present an adult experience and a solid view about what you have just experienced for the first time on your own. **The value is in the insights you, Abdallah, definitely have**, the rest is a disturbing noise. Unpleasant, but just a noise. – user3666197 Oct 20 '15 at 14:54