Reputation: 1254
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)
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()
.
Upvotes: 43
Views: 59003
Reputation: 416
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)
Upvotes: 13
Reputation: 25380
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:
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')
Upvotes: 67