Suppose I have the following array:
array = np.random.rand(5,3).flatten()
array
array([0.19274605, 0.46876174, 0.26670674, 0.55353007, 0.47098491,
0.41225302, 0.99921434, 0.43489851, 0.93929395, 0.85369836,
0.31313385, 0.41672712, 0.762171 , 0.06592526, 0.23157575])
These are the plotted data (with pyplot.plot()
):
Now, I need the line to have a different color depending on the value, for example, I need that for values between 0.2 and 0.4 the line is red, orange for values between 0.4 and 0.6 and blue for values between 0.8 and 1.
How can I do it? I need a solution that does not involve separating the array itself into several subarrays according the ranges and graphing them with the different colors.
NOTE: I've seen a lot of examples of multicolored lines but along the x axis, I need it but for the y axis.
Thanks.