2011-01-03 8 views

답변

78

그림과 축의 전체 배경을 투명하게하려면 그림을 fig.savefig으로 저장할 때 간단히 transparent=True을 지정할 수 있습니다.

예컨대 :

import matplotlib.pyplot as plt 
fig = plt.figure() 
plt.plot(range(10)) 
fig.savefig('temp.png', transparent=True) 

더 세밀하게 제어하려면, 당신은 단순히 그림의 facecolor 및/또는 알파 값을 설정하고 배경 패치를 축 수 있습니다. (우리는 0에 알파를 설정하거나 문자열이 아닌 객체 None로 ('none'에 facecolor을 설정할 수 있습니다, 패치가 완전히 투명하게 만들려면)!)

을 예 :

import matplotlib.pyplot as plt 

fig = plt.figure() 

fig.patch.set_facecolor('blue') 
fig.patch.set_alpha(0.7) 

ax = fig.add_subplot(111) 

ax.plot(range(10)) 

ax.patch.set_facecolor('red') 
ax.patch.set_alpha(0.5) 

# If we don't specify the edgecolor and facecolor for the figure when 
# saving with savefig, it will override the value we set earlier! 
fig.savefig('temp.png', facecolor=fig.get_facecolor(), edgecolor='none') 

plt.show() 

alt text

+3

'facecolor'를''none ''으로 설정하는 것은 저에게 효과적이지 않았습니다; 'alpha'를'0.0'으로 설정했습니다. –

+1

''베이스 맵 '에 대해 작동하지 않습니다. –