1. 程式人生 > >python利用Matplotlib,設定座標刻度大小,字型/設定圖例大小及字型/設定縱橫座標名稱及字型及大小

python利用Matplotlib,設定座標刻度大小,字型/設定圖例大小及字型/設定縱橫座標名稱及字型及大小

# coding: utf-8
import matplotlib.pyplot as plt

# figsize = 11, 9
# figure, ax = plt.subplots(figsize = figsize)
x1 =[0,5000,10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000]
y1=[0, 223, 488, 673, 870, 1027, 1193, 1407, 1609, 1791, 2113, 2388]
x2 = [0, 5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000]
y2 = [0, 214, 445, 627, 800, 956, 1090
, 1281, 1489, 1625, 1896, 2151] # 設定輸出的圖片大小 figsize = 11, 9 figure, ax = plt.subplots(figsize=figsize) # 在同一幅圖片上畫兩條折線 A, = plt.plot(x1, y1, '-r', label='A', linewidth=5.0) B, = plt.plot(x2, y2, 'b-.', label='B', linewidth=5.0) # 設定圖例並且設定圖例的字型及大小 font1 = {'family': 'Times New Roman', 'weight'
: 'normal', 'size': 23, } legend = plt.legend(handles=[A, B], prop=font1) # 設定座標刻度值的大小以及刻度值的字型 plt.tick_params(labelsize=23) labels = ax.get_xticklabels() + ax.get_yticklabels() # print labels [label.set_fontname('Times New Roman') for label in labels] # 設定橫縱座標的名稱以及對應字型格式 font2 = {'family'
: 'Times New Roman', 'weight': 'normal', 'size': 30, } plt.xlabel('round', font2) plt.ylabel('value', font2) plt.show()