-2

This question might be stupid but I can't find the answer. I'm using python and I want to plot a scatter graph where x is of size Nx, y of size Ny, z of size Nz and where for every point (x[i] , y[j], z[k]) I have an intensity I[i,j,k] which is a real number.

I would like to plot this scatter graph where every point of coordinates (x,y,z) has a color depending on the intensity

Polo Mali
  • 3
  • 2

1 Answers1

0

An easy way could be to use pyplot.cm.get_cmap(). Example below is for 2D, I let you figure out the rest.

from matplotlib import pyplot as plt

X = [1, 2, 3, 4]
Y = [1, 2, 2, 3]
# list-like of the intensities for each point
I = [2, 5, 7, 7]

# Create the colors
colors = plt.cm.get_cmap(None, len(list(set(I))))

colors_dict = dict()
count = 0
for elt in I:
    if elt not in colors_dict.keys():
        colors_dict[elt] = colors(count)
        count += 1
    else:
        continue

f, ax = plt.subplots(1, 1)

for k, x in enumerate(X):
    y = Y[k]
    i = I[k]
    dot_color = colors_dict[i]
    ax.scatter(x, y, s = 15, color = dot_color)

Output

It is likely that better ways than the one above exist.

Mathieu
  • 5,410
  • 6
  • 28
  • 55