Reputation: 99
I have an array (x,y,z) with x=1,2,...,100, y=1,2,...,100 and z with 100 values from [0,1]. Now I need to color the points (x,y) in dark red for the value of z near 0 and in dark blue for the value of z near 1. And in between it should go from dark red to light red then to white then to light blue then to dark blue. Can somebody please give me some advice?
Upvotes: 1
Views: 2635
Reputation: 11224
dark red for the value of z near 0 and in dark blue for the value of z near 1. And in between it should go from dark red to light red then to white then to light blue then to dark blue
Looking at the list of available colormaps, this seems to be RdBu
.
So here's an example scatterplot using RdBu
with 100 random x, y and z values, where x and y range from 1 to 100 and z from 0 to 1:
import matplotlib.pyplot as plt
import numpy as np
n = 100
x = np.random.randint(1, 100 + 1, n)
y = np.random.randint(1, 100 + 1, n)
z = np.random.random(n)
plt.scatter(x, y, c=z, cmap="RdBu")
plt.show()
Upvotes: 2