回答问题

如何获得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')
Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐