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'].
Add a comment
|
1 Answer
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()

1 Comment
hadrienj
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'])