【发布时间】:2021-01-08 05:31:09
【问题描述】:
我正在尝试绘制一个散点图,其中散点图中的每个点都应对应于我的 选择 的给定颜色的特定 阴影。 mpl 文档指出,如果我设置如下:
color = '0.7'
它给了我一个灰色阴影,具有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)
weights = list(weights)
print(min(weights),max(weights))
for i, shade in enumerate(weights):
plt.scatter(x[i],y[i],color=shade,marker = '+')
plt.show()
我正在以指数方式缩放这些权重,希望得到更好的变化。 所以,基本上,我的问题是:
- 如何将颜色更改为蓝色、红色或绿色,而不仅仅是灰度?
- 我遵循的灰度方法是否正确?
谢谢!
【问题讨论】:
标签: python matplotlib colors scatter-plot scatter