0
votes

I have two columns of the data frame. One column indicates the CPU node and the other indicates the threshold. I need to plot a scatter plot for that data frame. My question is how to get different colors on the threshold column. For example, 0-25% green, 25-50% light green, 50-75% yellow and above 75% red. As of now, I am getting only a single color.

Below is the data frame

cpu node  threshold
node 1      20
node 2      30
node 3      50
node 4      59
node 5      65
node 6      95

code for this I have written:

fig = go.Figure(go.Scatter(mode="markers", x=cpu node, y=threshold, marker_symbol='triangle-up',
                           marker_line_color="midnightblue", marker_color="lightskyblue",
                           marker_line_width=2, marker_size=15,
                           hovertemplate=cpu node))

enter image description here The above is giving only a single color with triangle markers.

Can anyone tell me how to get the graph that looks like this with customized colors i.e; ['green', 'light green', 'yellow', 'red'] based on the range of values enter image description here

1

1 Answers

1
votes

In this case, set the marker color to the value of the y-axis.

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(mode="markers", x=df['cpu node'], y=df['threshold'], marker_symbol='triangle-up',
                           marker_line_color="midnightblue", marker_color=df['threshold'],
                           marker_line_width=2, marker_size=15,
                           hovertemplate=df['cpu node']))

fig.show()

enter image description here