Reputation: 444
As I plot more curves using matplotlib, I see the curves/lines use the following colours and cycle around:
Can I cycle throughout more colours beyond just those 7?
Upvotes: 0
Views: 210
Reputation: 3893
You can use matplotlib
's Cycler
objects to interact with an underlying color-changing machinery. By creating your own cycler of desired length, you can make the turnaround as large as you want.
Here's how you can customize a color cycler to taste:
import matplotlib.pyplot as plt
food_colors = plt.cycler('color', ['tomato', 'olive', 'chocolate',
'salmon', 'plum', 'lime'])
plt.rc('axes', prop_cycle=food_colors)
The snippet above sets the default color cycle to food_colors
. Now all the newly drawn plots should be cycling through the six colors above.
import numpy as np
for i in range(20):
x, y, s = np.random.normal(10, 3, size=3)
plt.plot(x, y, 'o', ms=s*6, alpha=0.6)
plt.show()
Note that if you want to change the color cycle for a given axis only, you can use ax.set_prop_cycle(food_colors)
instead of changing rcParams
.
Upvotes: 2