網路上教學大部分都是使用自定義顏色,課堂導讀如何使用 matplotlib 官方內建顏色(colormap)
https://matplotlib.org/stable/users/explain/colors/colormap-manipulation.html
使用類似字典的方式等分取 8 個顏色
viridis = mpl.colormaps['viridis'].resampled(8)
specify_color = mpl.colormaps['xxxx'].resampled(8)
Colors 內建顏色組
資料來源:https://matplotlib.org/stable/users/explain/colors/colormaps.html
顏色無法直接使用,需要使用串列生成式,存成串列中。讓調色盤顏色變成真正的顏色數字
漸層顏色需要取樣
default_colors = mpl.colormaps['magma'].resampled(8)
default_colors_list = [default_colors(n) for n in range(8)]