0

I am trying to make scatter plot in python using viridis palette with only two values. 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')

sample plot

and it produce two colors - yellow and purple. The first one is not visible.

AAAA
  • 461
  • 6
  • 22

1 Answers1

1

You can create your custom colormap with only 2 colors:

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:

plot

trsvchn
  • 8,033
  • 3
  • 23
  • 30
  • Thank you, that almost answered my question as I still wanted to get colors from `viridis` palette, but i can work it out from here – AAAA Feb 10 '20 at 16:38