Issue
I want to know how to change plot(a,b)
coordinates to plot(a,b,color='red')
when the coordinates are above 40.0.
import matplotlib.pyplot as plt
a = [20.5,30.2,35.4,40.2,25.2,41.5,24.3,24.1,40.2]
b = list(range(len(a)))
plt.plot(b,a,marker='x',color='blue')
plt.show()
I don't know how to know the position value when the plot draws, and I'd like to try another way, but I don't know how to approach it.
Solution
To color the markers, you can create a color list that you pass to plt.scatter
for the c
parameter. I created the list using list comprehension. You didn't say how to handle the lines, so I just plotted them all as black in a separate plotting call.
import matplotlib.pyplot as plt
plt.close("all")
a = [20.5,30.2,35.4,40.2,25.2,41.5,24.3,24.1,40.2]
b = list(range(len(a)))
c = ["r" if value > 40 else "b" for value in a]
plt.plot(b, a, color="k")
plt.scatter(b, a, c=c, marker="x")
plt.show()
Answered By - jared
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.