Вы можете использовать цветовые палитры, определенные для matplit-lib:
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
Получить цвета и отсортировать их по hsv (или указать имена в нужном вам порядке - см. matplotlib.org named_colors. html пример
def get_hsv_colors():
# https://matplotlib.org/3.1.0/gallery/color/named_colors.html
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))), name)
for name, color in mcolors.CSS4_COLORS.items())
return [name for _, name in by_hsv]
Создание демонстрационных данных для составных y
*:
def get_y_data():
y1,y2,y3,y4,y5,y6 = np.random.rand(6,20)
y2 += y1 + 0.01
y3 += y2 + 0.01
y4 += y3 + 0.01
y5 += y4 + 0.01
y6 += y5 + 0.01
return y1,y2,y3,y4,y5,y6
Подключите их вместе:
# get the color-names from above or supply your own names:
cols_to_use = get_hsv_colors()[20::5] # skip the greys, only take every 5th name
# zipp the data with the corresponding color
matched_y_data = list( zip((y1,y2,y3,y4,y5,y6), cols_to_use))
# plot data with lines
for (y,c) in matched_y_data:
plt.plot(x, y, color=c)
plt.show()
# plot the same using fill_between
fig, ax1 = plt.subplots(1, 1, sharex=True, figsize=(6, 6))
# base line y -> 0:
ax1.fill_between(x, matched_y_data[0][0], 0, color=matched_y_data[0][1])
# intermediate lines y_n -> y_n+1:
for (idx, (y_data, col)) in enumerate(matched_y_data[:-1]):
ax1.fill_between(x, y_data, matched_y_data[idx+1][0], color=col)
# last line
mm = max( matched_y_data[-1][0] ) + 0.1
ax1.fill_between(x, matched_y_data[-1][0], mm, color=matched_y_data[-1][1])
ax1.set_xlabel('x')
fig.tight_layout()
plt.show()
для получения
![just plotted lines](https://i.stack.imgur.com/s0nzb.png)
и
![filled images](https://i.stack.imgur.com/LdKKP.png)
Вы можете получить цветовую схему, тщательно выбрав названия цветов:
# zipp the data with the corresponding color
matched_y_data = list(
zip((y1,y2,y3,y4,y5,y6),
"royalblue cornflowerblue lightsteelblue mistyrose lightsalmon tomato".split()))
![blue red scheme](https://i.stack.imgur.com/dCF6R.png)