2014-12-08 71 views

回答

5

size屬性:?

import matplotlib.pyplot as plt 
plt.xlabel('my x label', size = 20) 
plt.ylabel('my y label', size = 30) 
plt.title('my title', size = 40) 
plt.xticks(size = 50) 
plt.yticks(size = 60) 

實施例:

import numpy as np 
import matplotlib.pyplot as plt 
mu, sigma = 100, 15 
x = mu + sigma * np.random.randn(10000) 
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) 
plt.xlabel('Smarts', size = 20) 
plt.ylabel('Probability') 
plt.title('Histogram of IQ', size = 50) 
plt.text(60, .025, r'$\mu=100,\ \sigma=15$', size = 30) 
plt.axis([40, 160, 0, 0.03]) 
plt.xticks(size = 50) 
plt.yticks(size = 50) 
plt.grid(True) 
plt.show() 

enter image description here

---------- -------------- EDIT

使用相當情節

fig, ax = plt.plot() 
fig.suptitle('fig title', size = 80) 
ax.set_title('my title', size = 10) 
ax.set_xlabel('my x label', size = 20) 
ax.set_ylabel('my y label', size = 30) 
for tick in ax.xaxis.get_major_ticks(): 
    tick.label.set_fontsize(40) 
for tick in ax.yaxis.get_major_ticks(): 
    tick.label.set_fontsize(50) 

--------- LEGEND --------------

使用prop物業

ppl.legend(prop={'size':20}) 
plt.legend(prop={'size':20}) 

相同的命令..


例如:

import matplotlib.pyplot as plt 
import matplotlib as mpl 
from prettyplotlib import brewer2mpl 
import numpy as np 
import prettyplotlib as ppl 
np.random.seed(12) 
fig, ax = plt.subplots(1) 
fig.suptitle('fig title', size = 80) 
ax.set_title('axes title', size = 50) 
for tick in ax.xaxis.get_major_ticks(): 
    tick.label.set_fontsize(60) 
ax.set_ylabel("test y", size = 35) 
for i in range(8): 
    y = np.random.normal(size=1000).cumsum() 
    x = np.arange(1000) 
    ppl.plot(ax, x, y, label=str(i), linewidth=0.75) 
ppl.legend(prop={'size':30}) 
fig.savefig('plot_prettyplotlib_default.png') 

enter image description here

+0

感謝這個偉大工程,是不是也可以提高聯想的規模,和prettyplot lib是否有指定標題大小的替代語法,xlabel,ylabel和x和y蜱?當我將plt更改爲.ppt(對於prettyplot lib)時,它會失敗。 – yoshiserry 2014-12-08 03:46:52

+0

檢查答案編輯。這個傳說對於plt和ppl來說都是一樣的。 – 2014-12-08 11:40:22

+0

Thanks @Joao Paulo - 有沒有一種方法可以在df.plot(title = MyTitle)中指定標題的大小。如果我移動PLOT括號外的plt.title(MyTitle,size = 20),那麼在我的for循環中,它將在每個子圖上創建一個標題,我不希望這樣。我想爲一組子圖表示一個標題 - 但是我不知道如何在大括號圖標(title = MyTitle)中應用size屬性。 – yoshiserry 2014-12-08 21:37:57