Configuring matplotlib library uses Chinese drawing environment under Liunx

During the recent use matplotlib library need to use Chinese drawing, the Internet to find a good variety of ways, the ultimate solution in a way, in this record.

def conf_zh(font_name):
    from pylab import mpl
    mpl.rcParams['font.sans-serif'] = [font_name]
    mpl.rcParams['axes.unicode_minus'] = False

After playing the new main function call, call as follows:

if __name__ == "__main__":
    conf_zh("Droid Sans Fallback")
    t = arange(-5*pi, 5*pi, 0.001)
    y = sin(t)/t
    plt.plot(t, y)
    plt.title("你好")
    plt.show()

Using this method can be called Chinese font mapping

 

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159612.htm