2011-01-03 16 views

答えて

78

figureとaxesの両方の背景を透明にしたい場合は、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

'basemap'では動作しません –

関連する問題