2017-03-25 136 views
1

我正在製作一個繪圖,我需要的軸標題字體略大於圖例字體。我一直無法做到這一點。我正在使用一個樣式文件,並嘗試過:axes.titlesize,legend.fontsize和font.size(它們都會改變它們)。但是,他們似乎沒有給出所需的行爲。matplotlib 2.0更改軸獨立字體大小和圖例字體大小

如何可以將字體大小設置爲每個獨立地,例如,在下面的代碼:

import matplotlib.pyplot as plt 
import scipy 

#plt.style.use("myStyle.mplstyle.py") 

fig, ax = plt.subplots() 
xs = scipy.linspace(0,1,100) 
ys1 = scipy.sin(xs) 
ys2 = scipy.cos(xs) 

ax.plot(xs, ys1,"-",label="sin") 
ax.plot(xs, ys2,"-",label="cos") 
ax.set_xlabel("this is the title axis") 
ax.set_ylabel("this is the title axis 2") 
ax.legend() 

plt.show() 

回答

0

可用樣式設置可以在customization page

  • axes.titlesize被視爲改變的字體大小標題
  • axes.labelsize更改x和y標籤的字體大小
  • legend.fontsize改變圖例

實施例的字體大小:

import matplotlib.pyplot as plt 
import scipy 

plt.rcParams["axes.titlesize"] = 18 
plt.rcParams["legend.fontsize"] = 8 
plt.rcParams["axes.labelsize"] = 12 

fig, ax = plt.subplots() 
xs = scipy.linspace(0,1,100) 
ys1 = scipy.sin(xs) 
ys2 = scipy.cos(xs) 
ax.set_title("Title") 
ax.plot(xs, ys1,"-",label="sin") 
ax.plot(xs, ys2,"-",label="cos") 
ax.set_xlabel("this is the title axis") 
ax.set_ylabel("this is the title axis 2") 
ax.legend() 

plt.show() 

enter image description here