Seaborn プロットの背景色を設定する
- 
          
            Python で seaborn.set()関数を使用して Seaborn プロットの背景色を変更する
- 
          
            Python で seaborn.set_style()関数を使用して Seaborn プロットの背景色を変更する
 
このチュートリアルでは、Python の seaborn モジュールを使用して作成されたプロットの背景色を変更する方法を紹介します。
Python で seaborn.set() 関数を使用して Seaborn プロットの背景色を変更する
    
set() 関数は、さまざまな要素を追加し、プロットの美学を構成します。Seaborn の背景色を変更する直接的な議論や方法はありません。seaborn モジュールは matplotlib モジュール上に構築されているため、そのモジュールのパラメーターを seaborn プロットに使用できます。それらを set() 関数の rc パラメーターに辞書のキーと値のペアとして渡すことができます。
axes.facecolor および figure.facecolor パラメーターを使用して、背景色を変更します。軸はグラフが描画されるキャンバスと見なされ、図はさまざまな軸オブジェクトを含むオブジェクト全体です。
上記の方法は、以下のように使用できます。
import random
import seaborn as sns
import matplotlib as plt
s_x = random.sample(range(0, 100), 20)
s_y = random.sample(range(0, 100), 20)
sns.set(rc={"axes.facecolor": "cornflowerblue", "figure.facecolor": "cornflowerblue"})
sns.scatterplot(y=s_y, x=s_x)

Python で seaborn.set_style() 関数を使用して Seaborn プロットの背景色を変更する
seaborn モジュールではさまざまなテーマを利用できます。これらのテーマは私たちの問題の正確な解決策ではないかもしれませんが、それは私たちがフィギュアの背景を少しカスタマイズすることを可能にします。
set_style() 関数は、プロットのテーマを設定するために使用されます。次の値を受け入れることができます-dark、white、whitegrid、darkgrid、および tickers。dark および darkgrid パラメーターは、それぞれグリッドのない場合とある場合の灰色の背景を提供します。同様に、white および whitegrid パラメータについて結論を出すことができます。
例えば、
import random
import seaborn as sns
import matplotlib as plt
s_x = random.sample(range(0, 100), 20)
s_y = random.sample(range(0, 100), 20)
sns.set_style("darkgrid")
sns.scatterplot(y=s_y, x=s_x)

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
LinkedIn