python
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
#Example of use
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:
Recommended Posts