This article How to set the default color cycle for all subplots with matplotlib? teaches us how to use mpl.rcParams['axes.color_cycle'] = ['r', 'k', 'c'] to change the default colour 'r', 'k', 'c' cycle to red, black and cyan. However, how can I change the actual hex-triplets which 'r', 'k', 'c' represent? Say I want 'r' to represent #8F00FF (violet)? Or even better, how can I add colours, such that 'v' represent the hex-triplet #8F00FF? I hope to use them to implement them in mpl.rcParams['axes.color_cycle'].
Asked
Active
Viewed 1,800 times
0
Community
- 1
- 1
Mikkel Rev
- 863
- 3
- 12
- 31
1 Answers
2
You can specify the colors using hex notation directly in for the color cycle, like this:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from cycler import cycler # for mpl>2.2
mpl.rcParams['axes.prop_cycle'] = cycler(color=['r', '#8F00FF', '#A0F0A0'])
# for mpl < 2.2
#mpl.rcParams['axes.color_cycle'] = ['r', '#8F00FF', '#A0F0A0']
y = np.arange(5)
for i in range(7):
plt.plot(y + i, linewidth=5)
plt.show()

tom10
- 67,082
- 10
- 127
- 137
-
Not working. `axes.color_cycle is not a valid rc parameter`. I used: `from cycler import cycler` and `mpl.rcParams['axes.prop_cycle'] = cycler(color=['#2EBCE7', '#84EE29', '#FF8177'])` – hhh Aug 22 '19 at 22:22