2013-05-07 109 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.