Skip to content
Advertisement

How to discriminate between graphs in python?

I need to discriminate between 2 different graphs in python. Graphs are show below.

JavaScript

enter image description here

JavaScript

enter image description here

So, I want to divide these graphs into two categories, A or B. I want to use a property that can be used to discriminate between the two. If the user gives data set for GRAPH A or similar to GRAPH A, the output should be the graph and its category should be printed. Same goes for the GRAPH B. Following is the code for graph plotting. The category part is missing:

JavaScript

We can set a threshold value for if the graphs falls below it, the category is GRAPH B.

Advertisement

Answer

Since you load the full dataset you can do the categorization before your animation starts or you do it when needed. However, it is not clear what you mean by – or similar to GRAPH A –. To me it looks like both datasets differ by the length (or the fraction of the full dataset) along which they are at or close to the maximum level.

JavaScript

How do you want the identified category be printed? As a print command is straight forward, I will assume printing it into the plot itself:

JavaScript

That way you can implement it that plt.text is only called if the some_condition is met.

The category could for example only be displayed once you reach the falling flank of your graph:

JavaScript

Where (df.iloc[idx, 1] - df.iloc[idx-1, 1]) checks for a falling graph, (df.iloc[idx, 1] < value_threshold) makes sure that the graph fell beneath the threshold and (idx > 20) < 0 makes sure that the falling regions at the beginning of your graph are not giving false positives. Especially this last part depends strongly on how other data looks like. You probably have to tweak it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement