简体   繁体   English

"如何获得 matplotlib.pyplot.scatter 的默认蓝色?"

[英]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 ?如何获得matplotlib.pyplot.scatter中默认使用的蓝色阴影? When giving the keyword argument c='b' , it gives a darker shade of blue.当给出关键字参数c='b'时,它会给出更深的蓝色阴影。 In this documentation of matplotlib.pyplot.scatter , it says the default is supposed to be 'b' , yet it looks different.matplotlib.pyplot.scatter的这个文档中,它说默认应该是'b' ,但它看起来不同。

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.我正在使用 Python 3.5 和 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() .我问这个的原因是因为我想在用plt.plot()一个一个地绘制一些点时使用相同的蓝色。

The default colour cycle was changed in matplotlib version 2 as shown in the docs . matplotlib 版本 2 中的默认颜色循环已更改,如文档中所示。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM