0

I have a scatter graph of the following format:

BPT Diagram

Each point on that diagram represents a galaxy with a property known as a star formation rate. I wish to prescribe a colour map dependent on this variable, i.e., for higher SFRs the colour becomes bluer and for lower SFRs the colour becomes redder. (Ignore the binned histogram part for this exercise.)

How would I achieve this? Would I need to create and modify my own cmap?

GCien
  • 2,221
  • 6
  • 30
  • 56

1 Answers1

2

you just want a scatter plot of points with x and y coordinates and a colour representing a third variable?

this is what scatter is for, just use:

import matplotlib.pyplot as plt

plt.scatter(x, y, c=z, cmap='jet')

you can give it any other colormap, all possibilities are shown here: http://matplotlib.org/examples/color/colormaps_reference.html

here a small example:

import matplotlib.pyplot as plt
import numpy as np
x = numpy.random.normal(0, 2, 100)
y = numpy.random.normal(0, 2, 100)
r = np.sqrt(x**2 + y**2)
plt.scatter(x, y, c=r, cmap='jet')

this would give you 100 2d-gaussian distributed points with colors depending on the distance to (0,0)

MaxNoe
  • 14,470
  • 3
  • 41
  • 46
  • Hi Max, many thanks for your answer. I have one question, does the cmap then represent the incremental changes in the third variable, i.e., z=3 and z=3.01...do they have the same rough colour? But will z=3 and z=4 be distinctly different (either a shade of or a totally different colour?) – GCien Jul 22 '14 at 18:12
  • ValueError: Color array must be two-dimensional – GCien Jul 22 '14 at 20:13
  • the default is, that the colorbar goes linear from min(z) to max(z). Have a look at the color bars and try simple examples, like the one i edited in my post. with the vmin and vmax arguments you can set, which values are at the top and bottom of the color bar. For the Error you should present code. – MaxNoe Jul 22 '14 at 20:17