Ricky Robinson
Ricky Robinson

Reputation: 22933

Matplotlib: assign an ever different colour

In Matplotlib, I have several sets of points to fill in with different colours, one per set. Now, the number of sets varies, so I would like to make sure that that the same colour doesn't appear more than once in the same plot.

Right now I just do:

colors = itertools.cycle(['r','g','b','c','y','m'])
# ...
ax.plot(Xs_for_a_set, Ys_for_a_set, c=colors.next())

... but I am limited to that number of colors. From the documentation I don't get how to specify a random color in RGB...

Upvotes: 1

Views: 87

Answers (1)

sedavidw
sedavidw

Reputation: 11741

You can specify the color as a hex value in a string.

color = '#eeefff'

Using this you essentially have access to all colors via RGB and can create as many colors as you need

Upvotes: 1

Related Questions