Transform two lists of data into a graph with two parallel lines

0

Galera. I have been trying to do something that is very simple in Excel, but not in Python.

I have two lists. Line1 = [1,1,1,0,1,0,1] and Line2 = [0,0,0,0,1,1,1]

What I need to do is create a chart with these two lists and put them in parallel. Like a progress chart. Example 1 , #,

asked by anonymous 12.05.2018 / 17:04

1 answer

3

You can use the matplotlib library to plot the graph, see:

import matplotlib.pyplot as plt

def obterProgresso( linha ):
    p = [ 0 ]
    x = 0
    for i in linha:
        if i == 0:
            x-=1
        else:
            x+=1
        p.append(x)

    return p;


Linha1 = [1,1,1,0,1,0,1]
Linha2 = [0,0,0,0,1,1,1]

Prog1 = obterProgresso( Linha1 )
Prog2 = obterProgresso( Linha2 )

print "Linha1 = ", Prog1
print "Linha2 = ", Prog2

plt.plot( Prog1, 'bo' );
plt.plot( Prog1, 'k--', color='blue' );

plt.plot( Prog2, 'ro' );
plt.plot( Prog2, 'k--', color='red' );

plt.grid(True)
plt.xlabel("Tempo")
plt.ylabel("Progresso")

plt.show()

Output:

Progressions:

Linha1 =  [0, 1, 2, 3, 2, 3, 2, 3]
Linha2 =  [0, -1, -2, -3, -4, -3, -2, -1]
    
12.05.2018 / 18:15