Learning Scientific Programming with Python (2nd edition)

P9.4.1: Coloured Hertzsprung-Russell diagram

Question P9.4.1

Use pandas' cut method to classify the stars in the data set of Problem P9.2.3 according to their temperature by placing them into the bins labeled M, K, G, F, A, B, and O with left edges (in K) at 2400, 3700, 5200, 6000, 7500, 10 000, and 30 000.

Hence modify the code in the solution to this problem to plot the stars in a color appropriate to their temperature by establishing the following mapping:

color_mapping = {'M': '#FFB56C', 'K': '#FFDAB5', 'G': '#FFEDE3', 'F': '#F9F5FF',
                 'A': '#D5E0FF', 'B': '#A2C0FF', 'O': '#92B5FF'}

Hint: pandas provides a map method for mapping input values from an existing column to output values in a new column using a dictionary.