简体   繁体   English

从散点图中的调色板中选择两种颜色

[英]Choosing two colors from palette in scatter plot

I am trying to make scatter plot in python using viridis palette with only two values.我正在尝试使用只有两个值的viridis调色板在 python 中制作散点图。 I really like the purple, but the yellow is bearly visible.我真的很喜欢紫色,但黄色是难看的。 is it possible to choose middle value (blue) and purple?是否可以选择中间值(蓝色)和紫色?

x_test = [1, 2, 3, 4]
y_test = [1, 2, 3, 4]
c_test = [0, 1, 0, 1]

plt.scatter(x = x_test, y = y_test, c = c_test,  alpha=1, cmap='viridis')

样地

and it produce two colors - yellow and purple.它产生两种颜色——黄色和紫色。 The first one is not visible.第一个不可见。

You can create your custom colormap with only 2 colors:您可以仅使用 2 种颜色创建自定义颜色图:

Code:代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors


x_test = [1, 2, 3, 4]
y_test = [1, 2, 3, 4]
c_test = [0, 1, 0, 1]

mycmap = colors.ListedColormap(['purple', 'blue'])

plt.scatter(x = x_test, y = y_test, c = c_test,  alpha=1, cmap=mycmap, s=100)

Plot:阴谋:

阴谋

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM