How to get default blue colour of matplotlib.pyplot.scatter?

Question:

How do I get the shade of blue that is used as default in matplotlib.pyplot.scatter? When giving the keyword argument c='b', it gives a darker shade of blue. In this documentation of matplotlib.pyplot.scatter, it says the default is supposed to be 'b', yet it looks different.

See example below:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(-1, 0)
ax.text(-1, 0, 'Default blue')
ax.scatter(1, 0, c='b')
ax.text(1, 0, 'Darker blue')
ax.set_xlim(-2, 2)

Figure

I’m using Python 3.5 with Matplotlib 2.0.0. The reason why I’m asking this, is because I would like to use the same blue colour when plotting some of the points one by one with plt.plot().

Asked By: Fabian Ying

||

Answers:

The default colour cycle was changed in matplotlib version 2 as shown in the docs.

Therefore, to plot the “new” default blue you can do 2 things:

fig, ax = plt.subplots()

ax.scatter(-1, 1)
ax.text(-0.9, 1, 'Default blue')

ax.scatter(1, 1, c='#1f77b4')
ax.text(1.1, 1, 'Using hex value')

ax.scatter(0, 0.5, c='C0')
ax.text(0.1, 0.5, 'Using "C0" notation')

ax.set_xlim(-2, 3)
ax.set_ylim(-1,2)
plt.show()

Which gives:

enter image description here

Alternatively you can change the colour cycle back to what it was:

import matplotlib as mpl
from cycler import cycler

mpl.rcParams['axes.prop_cycle'] = cycler(color='bgrcmyk')
Answered By: DavidG

As noted in the docs, the default color cycle is the "Tableau Colors". These can be accessed using 'tab:blue', 'tab:orange', 'tab:green', etc.

So applied to your example, it would be

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(-1, 0)
ax.text(-1, 0, 'Default blue')
ax.scatter(1, 0, c='tab:blue')
ax.text(1, 0, 'Also default blue')
ax.set_xlim(-2, 2)

(Credit to @Tulio Casagrande’s comment)

Answered By: Porter Bagley
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.