Emoji in Matplotlib figures on OS X

后端 未结 1 937
广开言路
广开言路 2021-01-15 03:55

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

相关标签:
1条回答
  • 2021-01-15 04:50

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

    0 讨论(0)
提交回复
热议问题