[英]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')
As noted in the docs<\/a> , the default color cycle is the "Tableau Colors".如
文档<\/a>中所述,默认颜色循环是“Tableau 颜色”。 These can be accessed using
'tab:blue'<\/code> ,
'tab:orange'<\/code> ,
'tab:green'<\/code> , etc.
这些可以使用
'tab:blue'<\/code> 、
'tab:orange'<\/code> 、
'tab:green'<\/code>等来访问。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.