LoginSignup
4
4

More than 3 years have passed since last update.

python で虹色の6桁カラーコードを生成

Posted at

動機

グラフを描く時、カラフルに点や線の色を変えたくなったのですが、グラフ描画ツールの色パレットには数種類しか色が用意されていなかったりします。
そこで、虹色のカラーコードを自分で生成できるようにしました。

コード

import colorsys

HSV_tuples = [(x*1.0/N, 1.0, 1.0) for x in range(N)]
RGB_tuples = ['#%02x%02x%02x' % (int(x[0]*255), int(x[1]*255), int(x[2]*255)) for x in list(map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples))]

生成結果

N=24で生成した結果

['#ff0000', '#ff3f00', '#ff7f00', '#ffbf00', '#ffff00', '#bfff00', '#7fff00', '#3fff00', '#00ff00', '#00ff3f', '#00ff7f', '#00ffbf', '#00ffff', '#00bfff', '#007fff', '#003fff', '#0000ff', '#3f00ff', '#7f00ff', '#bf00ff', '#ff00ff', '#ff00bf', '#ff007f', '#ff003f']

bokeh_plot (10).png

4
4
1

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
4
4