Skip to content Skip to sidebar Skip to footer

How To Access Colors From A Style Used By Pyplot?

I can set the color style for pyplot using import matplotlib.pyplot as plt plt.style.use('tableau-colorblind10') And list the available color styles using plt.style.available Bu

Solution 1:

You can refer to the cycle colours as c1, c2 etc. Ie plt.plot(x, sqrx, color='C1', label='sqrx')

Solution 2:

Try:

plt.style.library['tableau-colorblind10']

[Out]:
RcParams({'axes.prop_cycle': cycler('color', ['#006BA4', '#FF800E', '#ABABAB', '#595959', '#5F9ED1', '#C85200', '#898989', '#A2C8EC', '#FFBC79', '#CFCFCF']),
          'patch.facecolor': '#006BA4'})

Thus, the color should be #006BA4 and set it to the line you wanna:

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from numpy import pi, sin, cos

plt.rcParams['figure.dpi'] = 200

plt.style.use('tableau-colorblind10')

x = np.linspace(0, pi, 100)
sinx = [sin(xi) for xi in x]
cosx = [cos(xi) for xi in x]
sqrx = [xi*xi for xi in x]

plt.plot(x, sinx, label='sinx')
plt.plot(x, cosx, label='cosx')
plt.plot(x, sqrx, color='#006BA4', label='sqrx')
plt.legend()

enter image description here

Post a Comment for "How To Access Colors From A Style Used By Pyplot?"