Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 865
Fabian Ying Avatar asked Nov 02 '17 11:11

Fabian Ying


People also ask

What are the default Colours in matplotlib?

The default interactive figure background color has changed from grey to white, which matches the default background color used when saving. in your matplotlibrc file.

How do I change the color of my PLT scatter?

To change the color of a scatter point in matplotlib, there is the option "c" in the function scatter.

How do I set the default style in matplotlib?

plt. style. use('default') worked for me. As I understand this, it tells matplotlib to switch back to its default style mode.


1 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') 
like image 57
DavidG Avatar answered Oct 08 '22 08:10

DavidG