How to change the color of a curve when the values increase?

Asked

Viewed 294 times

0

I have a data set. Sometimes some values increase compared to the previous ones.

resultsCos = [(0, 0.4235497237569061), (0.005, 0.4235497237569061), (0.01, 0.4238950276243094), (0.015, 0.42382596685082874), (0.02, 0.42375690607734806), (0.025, 0.42230662983425415), (0.03, 0.4210635359116022), (0.035, 0.41671270718232045), (0.04, 0.40835635359116024), (0.045, 0.3966850828729282), (0.05, 0.3770027624309392), (0.055, 0.3546270718232044), (0.1, 0.25041436464088396), (0.06, 0.3301795580110497), (0.065, 0.30738950276243093), (0.07, 0.2892955801104972), (0.075, 0.27603591160220997), (0.08, 0.2653314917127072), (0.09, 0.2553867403314917)]

I managed to make a chart with the following code:

import matplotlib.pyplot as plt
import seaborn as sns
# plot results Cosinus similarity
target = resultsCos
zip(*target)
plt.scatter(*zip(*target))
plt.xlabel('treshold/distance')
plt.ylabel('accuracy')
plt.title('Accuracy of cosine according to the distance')
plt.tight_layout()
plt.show()

introducir la descripción de la imagen aquí

But we didn’t really notice when there was an improvement, and I’d like to highlight that.

How to change the color of a curve when the values increase? And return them to the original color when they do not increase?

What is the method to change the color according to the previous value?

  • You can analyze the derivative of your function. When the derivative is positive, it has growth in the data; if negative, decrease and, when null, the data remained unchanged.

1 answer

1

Just use the data as color input and change the colormap of the graph. For example below:

import numpy as np
import matplotlib.pyplot as plt

#Meus dados randomicos
x = np.random.random(10)
y = np.random.random(10)

#Mude o COLORMAP aqui
plt.cool()
plt.scatter(x, y,c=y)

As a result:

Usando Cool colormap

In addition, you can have more elaborate analysis to define the color of the dots, as suggested in commenting. However, the final color change process will probably be done using the colormap or by filling the dots individually and changing the color according to its value (or leaving as is, depending on what you want to show). Both can have the same effect if applied correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.