Since plotly and pyqtgraph do not have (or few?) Color palettes, it is more difficult to specify colors than matplotlib. This time, I will introduce a module that allows you to easily create color gradations.
Mac OS Python 3.8.5 colour 0.1.5
pip install colour
All will be red.
from colour import Color
Color('red')
Color(red=1)
Color('#f00')
Color('#ff0000')
Color(rgb=(1, 0, 0)) # 0~1
Color(hsl=(0, 1, 0.5)) # 0~1
Color(Color('red'))
from colour import Color
c = Color('red') # <class 'colour.Color'>
Gets the value of c
.
RGB
rgb = c.get_rgb() # (1.0, 0.0, 0.0), tuple
rgb_hex = c.get_hex() # #f00, str
rgb_hex_long = c.get_hex_l() # #ff0000, str
HSL
hsl = c.get_hsl() #hsl color space(0.0, 1.0, 0.5), tuple
hue = c.get_hue() #Hue 0.0, float
saturation = c.get_saturation() #Saturation 1.0, float
luminance = c.get_luminance() #Luminance 0.5, float
red = c.get_red() # 1.0, float
blue = c.get_blue() # 0.0, float
green = c.get_green() # 0.0, float
c = Color('red') # c = red
Rewrite the value of c
c.set_blue(1) # c = magenta, set_red(), set_green()There is also
c.set_saturation(0.5) #Change saturation, c = #bf40bf, 0~Between 1
c.set_luminance(0.2) #Change brightness, c = #4c194c, 0~Between 1
#The value is overwritten
c.set_rgb((1, 0, 0))
c.set_hsl((0, 1, 0.5))
Color('red') == Color('blue')
False
Color('red') == Color('red')
True
Color('red') != Color('blue')
True
Color('red') != Color('red')
False
Specify the start color, end color, and the number of divisions
# red -Between blue
red = Color('red')
blue = Color('blue')
#5 divisions[<Color red>, <Color yellow>, <Color lime>, <Color cyan>, <Color blue>]
red_blue = list(red.range_to(blue, 5))
# black -Between white
black = Color('black')
white = Color('white')
#6 divisions[<Color black>, <Color #333>, <Color #666>, <Color #999>, <Color #ccc>, <Color white>]
black_white = list(black.range_to(white, 6))
Since matplotlib and seaborn can specify many colors from the beginning, you may not use them much. I think it can be used for plotly.
from colour import Color
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
red = Color('red')
blue = Color('blue')
red_blue = list(red.range_to(blue, 100))
for num, color in enumerate(red_blue, 1):
ax.plot([i for i in range(10)],
[i * num for i in range(10)],
c=color.get_hex_l())
plt.show()
Recommended Posts