0
1

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 3 years have passed since last update.

[python] 16進数表記のRGB値を暗くするメソッド

Posted at
def darken(rgb, rate=0.5):
    rgb = rgb.replace('#', '')
    s = '#'
    for i in [0,2,4]:
        c = rgb[i:i+2]
        c = int(c, 16)
        c = int(c * rate)
        c = format(c, '02x')
        s += c
    return s

# 使用例
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
color_orig = [
    '#C5DAEE',
    '#ABCFE5',
    '#8DC0DD',
    '#6AADD5',
    '#4F9BCB',
    '#3787C0',
    '#2070B4',
    '#0F5BA3',
    '#08458B',
    '#08306B',
]
color = [
    [darken(c) for c in color_orig],
    color_orig,
]
df = pd.DataFrame([np.ones(10), np.ones(10)], columns=[x[1] + '\n' + x[0] for x in np.array(color).T])
df.T.plot.bar(color=color, stacked=True)
plt.legend().remove()
plt.yticks([])
plt.xticks(rotation=0)
plt.show()

out:

スクリーンショット 2021-01-06 午後2.59.40.png

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?