Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ プロットの装飾 | Seabornによるプロット
Pythonによる究極の可視化
セクション 5.  3
single

single

bookプロットの装飾

メニューを表示するにはスワイプしてください

スタイルの設定

seaborn では、プロットのビジュアルスタイルを設定するために set_style() 関数を提供しています。この関数には、必須パラメータである style が必要です。style パラメータには、いくつかの事前定義されたオプションがあり、それぞれ異なるスタイルを表します。

  • 'white'
  • 'dark'
  • 'whitegrid'
  • 'darkgrid'
  • 'ticks'

これらを自由に試すことができます:

12345678910
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
copy

パレットの設定

もう一つのオプションとして、seabornset_palette() 関数を使ってプロット要素の色を変更できます。ここでは、唯一の必須パラメータである palette に注目します。

  • 円形パレット: 'hls', 'husl';
  • 知覚的に均一なパレット: 'rocket', 'magma', 'mako' など;
  • 発散型カラーパレット: 'RdBu', 'PRGn' など;
  • 連続型カラーパレット: 'Greys', 'Blues' など。
Note
さらに学ぶ

さまざまなパレットについてさらに詳しく知りたい場合は、 「Choosing color palettes」の記事をご覧ください。

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
copy

コンテキストの設定

seabornライブラリには、set_context()という別の関数があります。これは、ラベル、およびプロットの他の要素のサイズなどに影響します(全体のスタイルには影響しません)。

最も重要なパラメータはcontextで、これはパラメータのdictまたは事前設定されたセット名を表すstringのいずれかです。

デフォルトのcontext'notebook'です。他に利用可能なコンテキストとしては、'paper''talk''poster'があり、これらは本質的にnotebookパラメータのスケールバージョンです。

1234567891011121314151617
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
copy
Note
さらに学ぶ

さらに詳しくは、 set_context() ドキュメントを参照。

タスク

スワイプしてコーディングを開始

  1. 正しい関数を使用してスタイルを 'dark' に設定してください。
  2. 正しい関数を使用してパレットを 'rocket' に設定してください。
  3. 正しい関数を使用してコンテキストを 'talk' に設定してください。

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  3
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt