This is trying to answer all your questions. The code below shows no more than 7 colors. If you need more, you should create a simpler generator, as shown in another answer.
import numpy as np
from matplotlib import pyplot as plt
def get_color():
for item in ['r', 'g', 'b', 'c', 'm', 'y', 'k']:
yield item
x = 0.3 * np.array(range(40))
color = get_color()
for group in range(5):
y = np.exp2(x + 0.5 * group)
z = np.polyfit(x, y, 6)
p = np.poly1d(z)
acolor = next(color)
plt.scatter(x, y, color=acolor, marker='o')
plt.plot(x, p(x), acolor + '-', label=str(group))
plt.legend()
plt.xlim((0, 15))
plt.show()

The generator in the above code is a bit redundant for an example, but it provides a structure for more complex calculation. If you need only a few colors, you can use a simple iterator
>>> color = iter(list_of_colors)
>>> acolor = next(color)
and if you need an infinite loop, you can use itertools.cycle:
>>> from itertools import cycle
>>> color = cycle(['r', 'g', 'b', 'c', 'm', 'y', 'k'])
>>> next(color)
'r'
>>>
: n . , , , . , get_color :
import colorsys
import numpy as np
from matplotlib import pyplot as plt
def get_color(color):
for hue in range(color):
hue = 1. * hue / color
col = [int(x) for x in colorsys.hsv_to_rgb(hue, 1.0, 230)]
yield "#{0:02x}{1:02x}{2:02x}".format(*col)
x = 0.3 * np.array(range(40))
color = get_color(15)
for group in range(15):
y = np.exp2(x + 0.5 * group)
z = np.polyfit(x, y, 6)
p = np.poly1d(z)
acolor = next(color)
plt.scatter(x, y, color=acolor, marker='o')
plt.plot(x, p(x), color=acolor, linestyle='dashed', label=str(group))
plt.legend()
plt.xlim((0, 15))
plt.show()
15 .

, , , /. , :
for hue in range(0, color*3, 3):
- ...