Q: How can I change the color of a graph base on a value from another column? I have a data set containing max values over a certain height caused at different moments. I'm trying to visualize in a graph what the cause and max value is over the height. See the example below.
Say multiple people are in an elevator rolling a dice. Each time they save who threw the best score and make a graph of this.
Example Data:




Height[m]
Dice
Name




2
3
Tim


3
6
John


4
2
Lisa


5
1
John


6
5
Lisa




Now I would like to create a line plot like:
plt.plot(Dice, Height) visualizing the maximum thrown value over the height. However I would like to change the color of the line based upon the name of the person who threw the dice, showing directly who threw the highest at each height. Is this possible?
p.s. I prefer the graph to be a line however a scatter is also ok if it makes it easier.

A: I agree with the comments; Doing a scatterplot is the way to go.
If you do want a lineplot (the lines, while not corresponding to any data can aid the eye in finding data points), there is ambiguity as to how to color the lines, i.e. color them with the person before, or after.
That said, here is an implementation that colors the lines according to the person that just threw the dice:
# dummy data:

df = pd.DataFrame({'Height[m]':range(100), 'Dice':np.random.choice(np.arange(6), size=100),
              "Name": np.random.choice(['John', 'Tim', 'Lisa'], size=100)})

colors ={
    "Tim": 'red',
    'John': 'orange', 
    'Lisa': "green"
}

#scatterplot with color-coded markers
plt.scatter(df['Height[m]'], df['Dice'], c=[colors[name] for name in df['Name']])

# lineplot with individually colored line segments    
for a in df.index[:-1]:
    plt.plot([df.loc[a, 'Height[m]'], df.loc[a+1, 'Height[m]']], [df.loc[a, 'Dice'], df.loc[a+1, 'Dice']], color=colors[df.loc[a+1, 'Name']])

