Matplotlib散点图中的条件颜色

7
1个回答

9

您需要标记等于1的值并绘制图表:

import matplotlib.pyplot as plt
import numpy as np

# test data
t = np.linspace(0, 2 * np.pi, 30)
x = np.sin(t)
x[3] = 1
y = np.cos(t)

# indices for 'bad' values
indices = x == 1
# calc colors from jet cmap
cmap = plt.get_cmap('jet')
colors = cmap((y - y.min()) / y.ptp())

# normal values
plt.scatter(t[~indices], x[~indices], c = colors[~indices], cmap = cmap)
# bad values
plt.scatter(t[indices], x[indices], c = 'grey')
plt.show()

在此输入图片描述

t、x和y数组代表Pandas序列。


非常完美!非常感谢。 - MattnDo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接