如何获取 matplotlib.pyplot.scatter 的默认蓝色?
·
回答问题
如何获得matplotlib.pyplot.scatter
中默认使用的蓝色阴影?当给出关键字参数c='b'
时,它会给出更深的蓝色阴影。在这个文档的matplotlib.pyplot.scatter
中,它说默认应该是'b'
,但它看起来不同。
请参见下面的示例:
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)
我正在使用 Python 3.5 和 Matplotlib 2.0.0。我之所以问这个,是因为我想在用plt.plot()
一一绘制一些点时使用相同的蓝色。
Answers
matplotlib 版本 2 中的默认颜色循环已更改,如文档中所示。
因此,要绘制“新”默认蓝色,您可以做两件事:
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()
这使:
或者,您可以将颜色循环更改回原来的样子:
import matplotlib as mpl
from cycler import cycler
mpl.rcParams['axes.prop_cycle'] = cycler(color='bgrcmyk')
更多推荐
所有评论(0)