2012-02-19 6 views

답변

9

다음 스 니펫이 작동하는 것 같습니다.

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0, 5, 0.1); 
y = np.sin(x) 
fig1 = plt.figure(1) 
fig1.text(0.45, 0.95, "Case A", ha="center", va="bottom", size="medium",color="red") 
fig1.text(0.5, 0.95, "&", ha="center", va="bottom", size="medium") 
fig1.text(0.55,0.95,"Case B", ha="center", va="bottom", size="medium",color="blue") 
plt.plot(x, y) 
plt.show() 

matplotlib에 의해 생성 된 제목 함수는 하나의 텍스트 객체만을 포함하므로 하나의 글꼴 색상 만 가질 수 있습니다. 이것이 그림에 여러 텍스트 요소를 만드는 이유입니다.

3

하나 또한,하기 matplotlib의 figtext() 명령을 사용하여 다음과 같은 수

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0, 5, 0.1) 
for i in range(4): 
    plt.subplot(2,2,i+1) 
    plt.plot(x, np.sin((i+1)*x),'r') 
    plt.plot(x, np.cos(4*x/(i+1)),'b') 
    plt.title('(i+1)='+str(i+1)) 

plt.figtext(0.47, 0.96, "Case A", fontsize='large', color='r', ha ='right') 
plt.figtext(0.53, 0.96, "Case B", fontsize='large', color='b', ha ='left') 
plt.figtext(0.50, 0.96, ' vs ', fontsize='large', color='k', ha ='center') 
plt.show() 
관련 문제