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 › gallery › color › color_cycle_default.html
Colors in the default property cycle — Matplotlib 3.11.2 documentation
Display the colors from the default prop_cycle, which is obtained from the rc parameters. 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()
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.

Discussions

Default color cycler for plots should have more than 8 colors
In version 2.0 (coming soon...) ... make a cycle with any set of colors you like. Note, however, that in most cases trying to distinguish a large number of curves based on a large number of colors will not work well in conveying information to the viewer of the plot. Instead, if you can't reduce the number of curves, you can use a combination of colors, line styles, and line widths. For a preview, see http://matplotlib.org/devdo... More on github.com
🌐 github.com
November 24, 2016
Changing default colors of matplotlib for scatterplot
I think this is what your looking for: http://matplotlib.org/users/customizing.html More on reddit.com
🌐 r/learnpython
10
10
October 14, 2016
Change default color cycle
This is not yet a PR because I thought it might be good to discuss this first, but the default color cycle for plots uses very harsh primary colors. Would people be open to changing the default col... More on github.com
🌐 github.com
20
July 22, 2015
python - How to set the default color cycle for all subplots with matplotlib? - Stack Overflow
How can I set a default set of colors for plots made with matplotlib? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Matplotlib
matplotlib.org › stable › users › explain › artists › color_cycle.html
Styling with cycler — Matplotlib 3.11.2 documentation
axes.prop_cycle : cycler(color=['red', 'royalblue', 'gray']) For colors, a single string may be used either for one of the Named color sequences
🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colors.html
Specifying colors — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl th = np.linspace(0, 2*np.pi, 128) def demo(sty): mpl.style.use(sty) fig, ax = plt.subplots(figsize=(3, 3)) ax.set_title(f'style: {sty!r}', color='C0') ax.plot(th, np.cos(th), 'C1', label='C1') ax.plot(th, np.sin(th), 'C2', label='C2') ax.legend() demo('default') demo('seaborn-v0_8') The first color 'C0' is the title. 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.
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 7505
Default color cycler for plots should have more than 8 colors · Issue #7505 · matplotlib/matplotlib
November 24, 2016 - In version 2.0 (coming soon...) the default color cycle will have 10 colors, and you can always make a cycle with any set of colors you like. Note, however, that in most cases trying to distinguish a large number of curves based on a large number of colors will not work well in conveying information to the viewer of the plot. Instead, if you can't reduce the number of curves, you can use a combination of colors, line styles, and line widths. For a preview, see http://matplotlib.org/devdocs/examples/color/color_cycle_demo.html and http://matplotlib.org/devdocs/examples/color/color_cycle_default.html.
🌐
Reddit
reddit.com › r/learnpython › changing default colors of matplotlib for scatterplot
r/learnpython on Reddit: Changing default colors of matplotlib for scatterplot
October 14, 2016 -

So I'm making a scatterplot where in we plot A vs B and then based on a third variable (which is either, 0, 1, 2, 3 or 4) the dot on the graph has a different color. But one of the colors is yellow... which sucks for white backgrounds.

So I want to change the default colors picked by matplotlib that are assigned to each value of the third variable. The only thing I could find so far is to change the colormap with cmap=cm.xxx but that doesn't really work for me, since most cmaps still have yellow in it, or have just generally ugly colors.

So how do I change the default colors?

plt.scatter(df['A'],df['B'], s=5, c=df['third_variable'], edgecolors=(1,1,1,0))
🌐
MLJAR
mljar.com › blog › matplotlib-colors
9 ways to set colors in Matplotlib
November 21, 2022 - You can access the cycler colors by string "Cx", where x is a color index in the list.
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 - Matplotlib’s color cycle determines the sequence of colors used in plots. When multiple elements (lines, bars, or scatter points) are plotted without explicitly specifying colors, Matplotlib applies the default color cycle.
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 4754
Change default color cycle · Issue #4754 · matplotlib/matplotlib
July 22, 2015 - This is not yet a PR because I thought it might be good to discuss this first, but the default color cycle for plots uses very harsh primary colors. Would people be open to changing the default color cycle to something more esthetically pleasing such as one of the ones from colorbrewer2 or something similar to what seaborn uses?
Author: matplotlib
🌐
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()
🌐
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
🌐
Readthedocs
proplot.readthedocs.io › en › stable › cycles.html
Color cycles — ProPlot documentation
Occasionally, they are used as colormaps for qualitative or categorical data. Proplot’s color cycles are registered as DiscreteColormaps, and can be converted into matplotlib property cyclers for use with distinct plot elements using the Cycle constructor function.
🌐
Matplotlib
matplotlib.org › stable › users › explain › colors › colormaps.html
Choosing Colormaps in Matplotlib — Matplotlib 3.11.2 documentation
Cyclic: change in lightness of two different colors that meet in the middle and beginning/end at an unsaturated color; should be used for values that wrap around at the endpoints, such as phase angle, wind direction, or time of day. Qualitative: often are miscellaneous colors; should be used ...
🌐
TutorialsPoint
tutorialspoint.com › matplotlib › matplotlib_styling_with_cycler.htm
Matplotlib - Styling with Cycler
This example demonstrates how to define a default style (cycle through both colors and linestyles) for your plots using Cycler, making it easy to visualize all plots with different colors ('r', 'g', 'b', 'y') and linestyles ('-', '--', ':', '-.'). from cycler import cycler import matplotlib.pyplot as plt import numpy as np # Generate sample data x = np.linspace(0, 2 * np.pi, 50) offsets = np.linspace(0, 2 * np.pi, 4, endpoint=False) yy = np.transpose([np.sin(x + phi) for phi in offsets]) # Set default prop_cycle default_cycler = (cycler(color=['r', 'g', 'b', 'y']) + cycler(linestyle=['-', '--', ':', '-.'])) plt.rc('lines', linewidth=4) plt.rc('axes', prop_cycle=default_cycler) # Plot with the default color cycle plt.plot(yy) plt.title('Set Default Color Cycle') plt.show()
🌐
Petercbsmith
petercbsmith.github.io › color-tutorial.html
Plotting with Pride: colors in matplotlib
By default, plot colors cycle through the 10 Tableau Palette colors.
🌐
GitHub
gist.github.com › thriveth › 8560036
A color blind/friendly color cycle for Matplotlib line plots. Might want to shuffle it around a bit more,but already not it gives kinda good contrasts between subsequent colors, and shows reasonably well in colorblind filters (though not in pure monochrome). · GitHub
colors = { 'blue': '#377eb8', 'orange': '#ff7f00', 'green': '#4daf4a', 'pink': '#f781bf', 'brown': '#a65628', 'purple': '#984ea3', 'gray': '#999999', 'red': '#e41a1c', 'yellow': '#dede00' } ... Funny enough: matplotlib has already implemented ...
🌐
PyVista
docs.pyvista.org › examples › 02-plot › color_cycler.html
Color Cycling — PyVista 0.49.0 documentation
Cycle through colors when sequentially adding meshes to a plotter. Many plotting libraries like Matplotlib cycle through a predefined list of colors to colorize the data being added to the graphic.
🌐
Reddit
reddit.com › r/learnpython › why are scatter plot colors in matplotlib random when plotting in loop, but uniform when in list?
r/learnpython on Reddit: Why are scatter plot colors in Matplotlib random when plotting in loop, but uniform when in list?
November 21, 2020 -

Hello everyone,

I've noticed something interesting when it comes to a scatter plot colors in Matplotlib.

Lets take a basic example

import matplotlib.pyplot as plt


file1=[1,2,3,4,5]
file2=[1,2,3,4,5]
fig,ax=plt.subplots()
def fun():
    for x,y in zip(file1,file2):
        ax.scatter(x,y)
    plt.show()
def fun2():
    ax.scatter(file1,file2)
    plt.show()

When you are plotting in a loop:

fun()

The colors come out randomly. Each dot has its own color. However, if you scatter plot a list instead.

fun2()

Then all the colors are the same.

Why is this the case? The only thing I can think of is matplotlib takes each value in a loop as an independent species (i.e. it treats it as an individual case), whereas in a list each value is part of a group (i.e. it treats the list as an individual case, and all values in the list are part of that case). And thus, the colors are assigned per case basis.

Finally, I actually like the random colors, is there any way to get those colors back when plotting the list instead of within a loop?