matplotlib中文乱码解决

下列程序在Python3.6下运行通过。

# -*- coding=utf-8 -*-

from matplotlib import font_manager
import matplotlib.pyplot as plt;

if __name__ == '__main__':
    thread_num = [1, 3, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    throughput1 = [574.8695765, 878.0209408, 890.9727752, 892.219843, 890.1647918, 886.6329007, 884.769794, 882.6222708,
                   880.9602467, 877.2218384, 875.8964252, 875.2639468, 874.2978296]
    throughput2 = [18.22837677, 52.29950462, 88.11752763, 161.328, 235.0830, 233.0830, 231.0830, 229.0830, 227.0830,
                   225.0830, 223.0830, 221.0830, 219.0830062]
    # 指定字体为微软雅黑
    zh_font = font_manager.FontProperties(fname=r'c:\windows\fonts\msyh.ttc', size=11)

    # Plot the figure.
    line,  = plt.plot(thread_num, throughput1, color='cornflowerblue', linestyle='-', linewidth=3, marker='o', markersize=8,
             label='大对象')
    plt.plot(thread_num, throughput2, color='darkred', linestyle='-', marker='s', markersize=8, linewidth=3,
             label='小对象')
    plt.ylim(ymin=0)

    plt.ylabel('平均吞吐率(Mbit/s)', fontproperties=zh_font)
    plt.legend(loc=(0.78, 0.8), prop=zh_font)
    plt.xlabel('线程数', fontproperties=zh_font)
    plt.savefig('TestConcurrentPut10Mand10K.png')
 
    plt.show()



猜你喜欢

转载自blog.csdn.net/zk_j1994/article/details/78781328