小编Meg*_*egh的帖子

如何在matplotlib中为散点图中的每个点绘制不同的颜色深浅?

我正在尝试绘制散点图,其中散点图中的每个点都应对应于我选择的给定颜色的特定阴影。mpl 文档指出,如果我设置类似:

color = '0.7'
Run Code Online (Sandbox Code Playgroud)

它给了我一个灰色阴影,其缩放强度为0.7. 我正在从值在 0 到 1 之间的数组中读取颜色的强度,每个值对应于散点图中该点的强度。我的代码如下:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import math

tsne_embeddings = np.load("tsne_embeddings.npy")
labels = np.load('labels.npy')
weights = np.load('weights.npy')
# Scale the weights from 0 to 1
max_weight = max(weights)
min_weight = min(weights)
weights = (weights - min_weight)/(max_weight - min_weight)
print(tsne_embeddings.shape)
x = list(tsne_embeddings[:,0])
y = list(tsne_embeddings[:,1])
labels = list(labels)

weights = np.round(weights,decimals=2)
weights = (np.exp(weights) - 1)/(np.exp(1) - 1) …
Run Code Online (Sandbox Code Playgroud)

python scatter colors matplotlib scatter-plot

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

colors ×1

matplotlib ×1

python ×1

scatter ×1

scatter-plot ×1