2010-01-08 3 views
10

matplotlib의 그림 내 개별 서브 그림 주위에 테두리를 그리는 방법을 아십니까? 나는 pyplot을 사용하고 있습니다.matplotlib의 서브 그림 주위에 경계선 그리기

예 :

객체가 더 'edgecolor을'이없고, 나도 그림 수준에서 줄거리를 간략하게 설명 할 수있는 방법을 찾을 수가 없어 축 ..하지만
import matplotlib.pyplot as plt 
f = plt.figure() 
ax1 = f.add_subplot(211) 
ax2 = f.add_subplot(212) 
# ax1.set_edgecolor('black') 

.

실제로 mpl 코드를 래핑하고 어떤 subplot을 선택했는지에 따라 컨텍스트를 갖고 싶은 wx UI를 컨트롤에 추가하고 있습니다. 즉 사용자가 그림 캔버스 내에서 하위 그림을 클릭합니다. - 하위 그림이 '선택'되어 있습니다 (외곽선이 그려지고 이상적으로 톱니가 있음). - GUI 업데이트로 특정 하위 그림을 수정하는 컨트롤을 표시합니다.

답변

8

기본적으로 축 바깥 쪽에서 그립니다.

나는 이것을 here에서 수정했다. 거기에 하드 코딩 된 "퍼지 요인"을 사용 했으므로 정리가 필요합니다.

#!/usr/bin/env python 
from pylab import * 

def f(t): 
    s1 = cos(2*pi*t) 
    e1 = exp(-t) 
    return multiply(s1,e1) 

t1 = arange(0.0, 5.0, 0.1) 
t2 = arange(0.0, 5.0, 0.02) 
t3 = arange(0.0, 2.0, 0.01) 

figure(figsize=(4, 4)) 
sub1 = subplot(211) 
l = plot(t1, f(t1), 'bo', t2, f(t2), 'k--', markerfacecolor='green') 
grid(True) 
title('A tale of 2 subplots') 
ylabel('Damped oscillation') 

## I ADDED THIS 
autoAxis = sub1.axis() 
rec = Rectangle((autoAxis[0]-0.7,autoAxis[2]-0.2),(autoAxis[1]-autoAxis[0])+1,(autoAxis[3]-autoAxis[2])+0.4,fill=False,lw=2) 
rec = sub1.add_patch(rec) 
rec.set_clip_on(False) 

subplot(212) 
plot(t3, cos(2*pi*t3), 'r.') 
grid(True) 
xlabel('time (s)') 
ylabel('Undamped') 

savefig('test.png') 

는 생산 :

enter image description here