keisukeのブログ

***乱雑です!自分用のメモです!*** 統計や機械学習の勉強と、読み物を書く練習と、備忘録用のブログ

matplotlibで背景の色や透明度を設定する - How to set the background color and transparency in matplotlib

参考:matplotlib公式のArtist tutorial
f:id:kaisk:20141130164243p:plain

JP

matplotlibでプロットの背景の色や透明度の設定方法:

>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()  # Figure
>>> ax = fig.add_subplot(211)  # Axes
>>> fig.patch.set_facecolor('blue')  # 図全体の背景色
>>> fig.patch.set_alpha(0.5)  # 図全体の背景透明度
>>> ax.patch.set_facecolor('green')  # subplotの背景色
>>> ax.patch.set_alpha(0.3)  # subplotの背景透明度

subplotの緑色の透明度が0.3と低いので図全体の背景色の青に負けていますね

EN

How to set the plot's background color or transparency in matplotlib:

>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()  # Figure
>>> ax = fig.add_subplot(211)  # Axes
>>> fig.patch.set_facecolor('blue')  # change the background color of the figure
>>> fig.patch.set_alpha(0.5)  # change the background transparency of the figure
>>> ax.patch.set_facecolor('green')  # change the background color of the subplot
>>> ax.patch.set_alpha(0.3)  # change the background transparency of the subplot

Because the transparency of subplot's background green is 0.3, it seems like blue which is the Figure's background color.