matplotlib: annotate plot with Emoji labels

前端 未结 1 1363
忘掉有多难
忘掉有多难 2020-12-21 14:32

I\'m using Python 3.4 in macOS. Matplotlib is supposed to support Unicode in labels, but I\'m not seeing Emojis rendered properly.

import matplotlib.pyplot a         


        
相关标签:
1条回答
  • 2020-12-21 14:51

    You problem here is that the default font have no good support for emojis.

    In plt.annotate function, you can add a parameter fontname to specify the typeface that has a good support for emojis.

    Following code are what I got on my Windows machine with some edits to your code, it seems that "Segoe UI Emoji" has been installed on my computer already.

    # this line is for jupyter notebook
    %matplotlib inline
    
    import matplotlib.pyplot as plt
    import numpy as np
    # config the figure for bigger and higher resolution
    plt.rcParams["figure.figsize"] = [12.0, 8.0]
    plt.rcParams['figure.dpi'] = 300
    data = np.random.randn(7, 2)
    plt.scatter(data[:, 0], data[:, 1])
    labels = '                                                                    
    0 讨论(0)
提交回复
热议问题