42

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().

2
  • 3
    The default colour cycle was changed in matplotlib 2. See this part of the docs
    – DavidG
    Commented Nov 2, 2017 at 11:46
  • this worked for me MY_DEFAULT_BLUE: str = '#1f77b4' e.g. axs.plot(x, y, marker='x', label=label, lw=linewidth, color='#1f77b4') Commented Oct 21, 2021 at 16:56

2 Answers 2

66

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')
1
12

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.