In matplotlib versions >= 1.5, you can print the rcParam called axes.prop_cycle:

print(plt.rcParams['axes.prop_cycle'].by_key()['color'])

# [u'#1f77b4', u'#ff7f0e', u'#2ca02c', u'#d62728', u'#9467bd', u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']

Or equivalently, in python2:

print plt.rcParams['axes.prop_cycle'].by_key()['color']

In versions < 1.5, this was called color_cycle:

print plt.rcParams['axes.color_cycle']

# [u'b', u'g', u'r', u'c', u'm', u'y', u'k']

Note that the default color cycle changed in version 2.0.0 http://matplotlib.org/users/dflt_style_changes.html#colors-in-default-property-cycle

Answer from tmdavison on Stack Overflow
🌐
Matplotlib
matplotlib.org › stable › users › explain › artists › color_cycle.html
Styling with cycler — Matplotlib 3.11.2 documentation
For colors, a single string may be used either for one of the Named color sequences ... from cycler import cycler cc = (cycler(color=list('rgb')) + cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d)
🌐
Matplotlib
matplotlib.org › stable › gallery › color › color_cycle_default.html
Colors in the default property cycle — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import TABLEAU_COLORS, same_color def f(x, a): """A nice sigmoid-like parametrized curve, ending approximately at *a*.""" return 0.85 * a * (1 / (1 + np.exp(-x)) + 0.2) fig, ax = plt.subplots() ax.axis('off') ax.set_title("Colors in the default property cycle") prop_cycle = plt.rcParams['axes.prop_cycle'] colors = prop_cycle.by_key()['color'] x = np.linspace(-4, 4, 200) for i, (color, color_name) in enumerate(zip(colors, TABLEAU_COLORS)): assert same_color(color, color_name) pos = 4.5 - i ax.plot(x, f(x, pos)) ax.text(4.2, pos, f"'C{i}': '{color_name}'", color=color, va="center") ax.bar(9, 1, width=1.5, bottom=pos-0.5) plt.show()
🌐
Matplotlib
matplotlib.org › stable › tutorials › intermediate › color_cycle.html
Styling with cycler — Matplotlib 3.7.2 documentation
November 10, 2021 - from cycler import cycler cc = (cycler(color=list('rgb')) * cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d) Results in: {'color': 'r', 'linestyle': '-'} {'color': 'r', 'linestyle': '--'} {'color': 'r', 'linestyle': '-.'} {'color': 'g', 'linestyle': '-'} {'color': 'g', 'linestyle': '--'} {'color': 'g', 'linestyle': '-.'} {'color': 'b', 'linestyle': '-'} {'color': 'b', 'linestyle': '--'} {'color': 'b', 'linestyle': '-.'} Download Python source code: color_cycle.py ·
🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colors.html
Specifying colors — Matplotlib 3.11.2 documentation
Each plot uses the second and third colors of each style's rcParams["axes.prop_cycle"] (default: cycler('color', [(0.12156862745098039, 0.4666666666666667, 0.7058823529411765), (1.0, 0.4980392156862745, 0.054901960784313725), (0.17254901960784313, 0.6274509803921569, 0.17254901960784313), (0.8392156862745098, 0.15294117647058825, 0.1568627450980392), (0.5803921568627451, 0.403921568627451, 0.7411764705882353), (0.5490196078431373, 0.33725490196078434, 0.29411764705882354), (0.8901960784313725, 0.4666666666666667, 0.7607843137254902), (0.4980392156862745, 0.4980392156862745, 0.4980392156862745), (0.7372549019607844, 0.7411764705882353, 0.13333333333333333), (0.09019607843137255, 0.7450980392156863, 0.8117647058823529)])).
🌐
Delft Stack
delftstack.com › home › howto › matplotlib › matplotlib color cycle
Color Cycle in Matplotlib | Delft Stack
December 21, 2022 - We have a property for working with lines in the color cycle iterable called ax._get_lines.color_cycle and the ax._get_patches_for_fill.color_cycle for working with patches. Matplotlib 1.5 and the later versions have changed to use the Cycler library.
🌐
Matplotlib
matplotlib.org › 3.1.1 › gallery › color › color_cycle_default.html
Colors in the default property cycle — Matplotlib 3.1.2 documentation
import numpy as np import matplotlib.pyplot as plt prop_cycle = plt.rcParams['axes.prop_cycle'] colors = prop_cycle.by_key()['color'] lwbase = plt.rcParams['lines.linewidth'] thin = lwbase / 2 thick = lwbase * 3 fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True) for icol in range(2): if icol == 0: lwx, lwy = thin, lwbase else: lwx, lwy = lwbase, thick for irow in range(2): for i, color in enumerate(colors): axs[irow, icol].axhline(i, color=color, lw=lwx) axs[irow, icol].axvline(i, color=color, lw=lwy) axs[1, icol].set_facecolor('k') axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2)) axs[0, icol].set_title('line widths (pts): %g, %g' % (lwx, lwy), fontsize='medium') for irow in range(2): axs[irow, 0].yaxis.set_ticks(np.arange(0, 10, 2)) fig.suptitle('Colors in the default prop_cycle', fontsize='large') plt.show()
🌐
Matplotlib
matplotlib.org › 1.2.1 › examples › api › color_cycle.html
api example code: color_cycle.py — Matplotlib 1.2.1 documentation
""" import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl yy = np.arange(24) yy.shape = 6,4 mpl.rc('lines', linewidth=4) fig = plt.figure() mpl.rcParams['axes.color_cycle'] = ['r', 'g', 'b', 'c'] ax = fig.add_subplot(2,1,1) ax.plot(yy) ax.set_title('Changed default color cycle to rgbc') ax = fig.add_subplot(2,1,2) ax.set_color_cycle(['c', 'm', 'y', 'k']) ax.plot(yy) ax.set_title('This axes only, cycle is cmyk') plt.show() Keywords: python, matplotlib, pylab, example, codex (see Search examples)
Top answer
1 of 4
217

In matplotlib versions >= 1.5, you can print the rcParam called axes.prop_cycle:

print(plt.rcParams['axes.prop_cycle'].by_key()['color'])

# [u'#1f77b4', u'#ff7f0e', u'#2ca02c', u'#d62728', u'#9467bd', u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']

Or equivalently, in python2:

print plt.rcParams['axes.prop_cycle'].by_key()['color']

In versions < 1.5, this was called color_cycle:

print plt.rcParams['axes.color_cycle']

# [u'b', u'g', u'r', u'c', u'm', u'y', u'k']

Note that the default color cycle changed in version 2.0.0 http://matplotlib.org/users/dflt_style_changes.html#colors-in-default-property-cycle

2 of 4
198

Often, there is no need to get the default color cycle from anywhere, as it is the default one, so just using it is sufficient.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t = np.arange(5)

for i in range(4):
    line, = ax.plot(t,i*(t+1), linestyle = '-')
    ax.plot(t,i*(t+1)+.3,color = line.get_color(), linestyle = ':')

plt.show()

In case you want to use the default color cycle for something different, there are of course several options.

"tab10" colormap

First it should be mentionned that the "tab10" colormap comprises the colors from the default color cycle, you can get it via cmap = plt.get_cmap("tab10").

Equivalent to the above would hence be

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t = np.arange(5)
cmap = plt.get_cmap("tab10")
for i in range(4):
    ax.plot(t,i*(t+1),   color=cmap(i), linestyle = '-')
    ax.plot(t,i*(t+1)+.3,color=cmap(i), linestyle = ':')

plt.show()

Colors from color cycle

You can also use the color cycler directly, cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']. This gives list with the colors from the cycle, which you can use to iterate over.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t = np.arange(5)
cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']

for i in range(4):
    ax.plot(t,i*(t+1),   color=cycle[i], linestyle = '-')
    ax.plot(t,i*(t+1)+.3,color=cycle[i], linestyle = ':')

plt.show()

The CN notation

Finally, the CN notation allows to get the Nth color of the color cycle, color="C{}".format(i). This however only works for the first 10 colors (N in [0,1,...9])

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t = np.arange(5)

for i in range(4):
    ax.plot(t,i*(t+1),   color="C{}".format(i), linestyle = '-')
    ax.plot(t,i*(t+1)+.3,color="C{}".format(i), linestyle = ':')

plt.show()

All codes presented here produce the same plot.

Find elsewhere
🌐
StrataScratch
stratascratch.com › blog › how-to-customize-matplotlib-colors-for-better-plots
How to Customize Matplotlib Colors for Better Plots? - StrataScratch
February 24, 2025 - The ColorBrewer palettes are available in Python via the colorcet and palettable libraries. The code below demonstrates the use of colorcet. It is used to select the glasbey_category10 categorical palette. (You can see all the colorcet palettes – both continuous and categorical – at this link.) The code then configures Matplotlib to cycle through the selected palette for plot lines and markers and creates a plot.
🌐
Matplotlib
matplotlib.org › 3.5.0 › tutorials › intermediate › color_cycle.html
Styling with cycler — Matplotlib 3.5.0 documentation
November 10, 2021 - from cycler import cycler cc = (cycler(color=list('rgb')) * cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d) Results in: {'color': 'r', 'linestyle': '-'} {'color': 'r', 'linestyle': '--'} {'color': 'r', 'linestyle': '-.'} {'color': 'g', 'linestyle': '-'} {'color': 'g', 'linestyle': '--'} {'color': 'g', 'linestyle': '-.'} {'color': 'b', 'linestyle': '-'} {'color': 'b', 'linestyle': '--'} {'color': 'b', 'linestyle': '-.'} Download Python source code: color_cycle.py ·
🌐
Robin's Blog
blog.rtwilson.com › easily-specifying-colours-from-the-default-colour-cycle-in-matplotlib
Easily specifying colours from the default colour cycle in matplotlib « Robin's Blog
November 14, 2019 - To get the colours in the default colour cycle you can simply use the strings 'C0', 'C1', 'C2' etc. So, in this case just · plt.fill_between(x_values, line2 - 5, line2 + 5, alpha=0.3, color='C1') The result looks far better now the colours match: I found out about this from a wonderful graphical ...
🌐
Petercbsmith
petercbsmith.github.io › color-tutorial.html
Plotting with Pride: colors in matplotlib
You can also use the string "CN", where N is the position in the color cycle, to get that specific color: matplotlib also has a built-in color cycle that is more accessible for those with color vision deficiency.
🌐
SciVision
scivision.dev › matplotlib-endless-cycle-colors
Matplotlib cycle plot colors endlessly | Scientific Computing
July 31, 2023 - import itertools import matplotlib.pyplot as plt import matplotlib.colors as mplcolors color_cycle = itertools.cycle(mplcolors.TABLEAU_COLORS) xy = [(x, x**1.2) for x in range(20)] # toy data ax = plt.figure().gca() for (x, y), color in zip(xy, color_cycle): ax.scatter(x, y, color=color) print(xy) plt.show()
🌐
Matplotlib
matplotlib.org › 2.0.2 › examples › color › color_cycle_demo.html
color example code: color_cycle_demo.py — Matplotlib 2.0.2 documentation
""" from cycler import cycler import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi) offsets = np.linspace(0, 2*np.pi, 4, endpoint=False) # Create array with shifted-sine curve along each column yy = np.transpose([np.sin(x + phi) for phi in offsets]) # 1. Setting prop cycle on default rc parameter plt.rc('lines', linewidth=4) plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) + cycler('linestyle', ['-', '--', ':', '-.']))) fig, (ax0, ax1) = plt.subplots(nrows=2) ax0.plot(yy) ax0.set_title('Set default color cycle to rgby') # 2. Define prop cycle for sing
🌐
Matplotlib
matplotlib.org › 3.1.1 › tutorials › intermediate › color_cycle.html
Styling with cycler — Matplotlib 3.1.2 documentation
May 1, 2020 - from cycler import cycler cc = (cycler(color=list('rgb')) * cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d) Results in: {'color': 'r', 'linestyle': '-'} {'color': 'r', 'linestyle': '--'} {'color': 'r', 'linestyle': '-.'} {'color': 'g', 'linestyle': '-'} {'color': 'g', 'linestyle': '--'} {'color': 'g', 'linestyle': '-.'} {'color': 'b', 'linestyle': '-'} {'color': 'b', 'linestyle': '--'} {'color': 'b', 'linestyle': '-.'} Download Python source code: color_cycle.py ·
🌐
O'Reilly
oreilly.com › library › view › matplotlib-for-python › 9781788625173 › 3609e125-fe04-45c3-88a1-a8492bfe0ca4.xhtml
Default color cycle - Matplotlib for Python Developers - Second Edition [Book]
April 24, 2018 - A color cycle is a list of colors used to control the color of a series of elements automatically, such as each data series in multiline plots. In Matplotlib 2.0, the default color cycle has expanded from 7 to 10 colors using the category10 ...
Authors: Aldrin YimClaire ChungAllen Yu
Published: 2018
Pages: 300
🌐
Tonysyu
tonysyu.github.io › mpltools › auto_examples › color › plot_cycle_cmap.html
Color cycle from a colormap — mpltools docs
By default, it alters the default color cycle, but if you pass it a plot axes, only the color cycle for the axes is altered. import numpy as np import matplotlib.pyplot as plt from mpltools import layout from mpltools import color n_lines = 10 # Change default color cycle for all new axes color.cycle_cmap(n_lines) figsize = layout.figaspect(aspect_ratio=0.5) fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=figsize) # Change color cycle specifically for `ax2` color.cycle_cmap(n_lines, cmap='pink', ax=ax2) x = np.linspace(0, 10) for shift in np.linspace(0, np.pi, n_lines): ax1.plot(x, np.sin(x - shift), linewidth=2) ax2.plot(x, np.sin(x - shift), linewidth=2) plt.show()
🌐
Matplotlib
matplotlib.org › 3.2.2 › gallery › color › color_cycler.html
Styling with cycler — Matplotlib 3.2.2 documentation
June 17, 2020 - from cycler import cycler import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi) offsets = np.linspace(0, 2*np.pi, 4, endpoint=False) # Create array with shifted-sine curve along each column yy = np.transpose([np.sin(x + phi) for phi in offsets]) # 1. Setting prop cycle on default rc parameter plt.rc('lines', linewidth=4) plt.rc('axes', prop_cycle=(cycler(color=['r', 'g', 'b', 'y']) + cycler(linestyle=['-', '--', ':', '-.']))) fig, (ax0, ax1) = plt.subplots(nrows=2, constrained_layout=True) ax0.plot(yy) ax0.set_title('Set default color cycle to rgby') # 2.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-plot-with-multiple-color-cycle-using-cycler-property-in-matplotlib
How to plot with multiple color cycle using cycler property in Matplotlib
from cycler import cycler import numpy as np from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from IPython.core.display import display · In this example, we will create two objects which will repeat the cycle after every four objects. Thus, after creating two objects, the last two will be the repeat of the first two objects. ... custom_cycler = cycler('color', ['g', 'blue', 'y', 'c']) + \ cycler('hatch', ['+*', 'xx', '+x', '+O.']) ax.set_prop_cycle(custom_cycler)