Issue
I have a custom color palette i created for my employer
pink = '#E5007E'
pink_80 = '#FFC7E6'
pink_60='#FF8FCC'
aqua='#00B4DF'
aqua_80='#C6F4FF'
pink_40='#FF56B3'
pink_d25='#AC005F'
aqua_60='#8CE9FF'
aqua_40='#53DEFF'
aqua_d25='#0087A7'
color_list = [pink, aqua,
aqua_80, pink_80,aqua_60, pink_60,aqua_40,pink_40,aqua_d25,pink_d25]
how do i make this the default color palette for all charts going forward? Is there such a way of saying "import color_list" and have matplotlib default to that list?
Solution
You need to modify Matplotlib's configuration file, matplotlibrc
. This file is stored on various locations, depending on the level you wish to apply your edits (globally, vs single environment). You can find the locations at this documentation page
Once you have located the file to modify, you open it and look for this line:
#axes.prop_cycle: cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])
You need to remove the first character #
, and copy the hex values without the #
character, like this:
axes.prop_cycle: cycler('color', ['E5007E', '00B4DF', 'C6F4FF', 'FFC7E6', '8CE9FF', 'FF8FCC', '53DEFF', 'FF56B3', '0087A7', 'AC005F'])
Save the file, open a Python interpreter:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-np.pi, np.pi)
plt.figure()
for i in range(10):
plt.plot(x, (i + 1) * np.cos(x), label=str(i))
plt.legend()
plt.show()
Now, the new color palette is going to be used everytime you load matplotlib.
Answered By - Davide_sd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.