0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

seabornのpaletteの作り方・使い方

Posted at

作成日:20220725
言語:Python

環境

Python 3.6.10 :: Anaconda, Inc.
seaborn 0.10.1

パレットの作成

パレットはリスト。リストの各要素は色の名前(blue、redなど)もしくはその色のRGB値。

import seaborn as sns
palette = sns.color_palette("RdPu",4) #パレット名、色の数を指定
sns.palplot(palette)

palette.jpg

print(palette)

で見てみると、RGBの値を指定した3要素のtupple(これで1色)が入ったリストになっている。今回は4色のパレットなので、リストの中にはtuppleが4つ入っている。

[(0.9898039215686275, 0.8149019607843138, 0.7984313725490196), (0.9780392156862745, 0.5803921568627451, 0.6941176470588235), (0.8870588235294118, 0.24470588235294116, 0.6), (0.6007843137254902, 0.00392156862745098, 0.4831372549019608)]```

色を直接指定したリストを作っても良い。

palette = ["red", "orange", "yellow", "green"]
sns.palplot(palette); plt.savefig('palette2.jpg')

palette2.jpg

print(palette)

の出力は当然のことながら次のようになる。

['red', 'orange', 'yellow', 'green']

詳しい使い方は下のリンクを参考のこと。

参考リンク

  1. paletteの使い方について
    https://qiita.com/SaitoTsutomu/items/c79c9973a92e1e2c77a7 Qiitaの日本語記事
    http://seaborn.pydata.org/tutorial/color_palettes.html seabornのtutorial

  2. 選べるパレット名一覧 (※パレット名はmatplotlibのcolormapから取ってきている)
    https://matplotlib.org/stable/tutorials/colors/colormaps.html matplotlibのtutorialより

  3. この他にも、自分の好きな色を1つ選んでグラデーションのパレットを作れたりする。
    http://seaborn.pydata.org/tutorial/color_palettes.html#custom-sequential-palettes seabornのtutorialの"custom sequencial palettes"のセクションより

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?