2013-05-07 176 views

回答

0

可以使用subplots命令來實現這一點,這可以像py.subplot(2,2,1)那樣簡單,其中前兩個數字描述圖的幾何圖形(2x2),第三個圖是當前圖號。一般來說,最好是明確指明,在下面的例子中

import pylab as py 

# Make some data 
x = py.linspace(0,10,1000) 
cos_x = py.cos(x) 
sin_x = py.sin(x) 

# Initiate a figure, there are other options in addition to figsize 
fig = py.figure(figsize=(6,6)) 

# Plot the first set of data on ax1 
ax1 = fig.add_subplot(2,1,1) 
ax1.plot(x,sin_x) 

# Plot the second set of data on ax2 
ax2 = fig.add_subplot(2,1,2) 
ax2.plot(x,cos_x) 

# This final line can be used to adjust the subplots, if uncommentted it will remove all white space 
#fig.subplots_adjust(left=0.13, right=0.9, top=0.9, bottom=0.12,hspace=0.0,wspace=0.0) 

Produces this image

注意,這意味着如預期,因爲你有兩個軸之類的東西py.xlabel可能無法正常工作。相反,您需要指定ax1.set_xlabel("..")這使代碼更易於閱讀。

更多實例可以發現here.