简体   繁体   English

Matplotlib中的表情符号可在OS X上显示

[英]Emoji in Matplotlib figures on OS X

I have an exotic task for Matplpoltlib for which I need to display emoji inside labels. 我对Matplpoltlib有一个奇特的任务,需要在标签内显示表情符号。 I am using OS X, so there is a good system-wide support of emoji. 我正在使用OS X,因此emoji对系统提供了很好的支持。 However, things do not work out with Matplotlib: currently, emoji get displayed as empty boxes. 但是,Matplotlib无法解决问题:目前,表情符号显示为空框。 I am using Python 3, so Unicode should not be a problem. 我正在使用Python 3,因此Unicode应该不是问题。 Thank you 😀 谢谢😀

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. 它背后的想法不是很困难,但是为了使其能够显示(至少在ubunto上),它给了我一些麻烦,因为并非所有字体都支持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. 从表情符号python包表情符号备忘单中 ,我挑选了三个作为示例,这是代码。

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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM