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

Смежные вопросы