Drkcore

11 08 2014 Python Tweet

ggplotっぽい配色

ggplotっぽい配色が欲しかったので探したらsofで見つけたがこれはRのコードなのでPythonで

colorsysというモジュールを使う。

でもこれは0-1の範囲の数字がタプルで返ってきて使いにくいので255をかけた後16進数表記にして返す関数を書いた。

from colorsys import hls_to_rgb

def color_list(n, l=0.65, s=1.0):
    return ['#%02x%02x%02x' % tuple(map(lambda x: int(x * 255), \
        hls_to_rgb((i + 3 - n)/ float(n), l, s))) for i in range(n)]

10個ほど生成させてみるといい感じ

■ ■ ■ ■ ■ ■ ■ ■ ■ ■

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021