-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_live_graph_infinite.py
72 lines (45 loc) · 1.93 KB
/
main_live_graph_infinite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import matplotlib.pyplot as plt
#Graph setup
plt.xlabel('iteration')
plt.ylabel('value')
plt.title('Graph')
#Variables
number = 1 # initial positive number
iterations = 0 # to count iteration
List_iteration= [0] # lists to plot
List_number= [0]
#Interaction
print('\n Do you want to start from a specific number [y/n] ?')
option_number=str(input(' default is 1, enter y or n to continue : '))
if (option_number == 'Y' or option_number == 'y'):
number =int(input(' Enter the number : '))
print('\n Press Ctrl + C any time to quit \n')
start=str(input(' Press Enter to begin ! \n'))
num = number
while True:
if(num%2) == 0: #if number is even make it odd
num = int(num/2)
iterations += 1 #increment
List_number.append(num) # Add number/value in list, every time
List_iteration.append(iterations) # Add iteration value/increment
plt.plot(List_iteration, List_number , 'b-o') #Pass varibles as arguments to plot, with graph style
plt.pause(0.0001) #pause for interval seconds
# graph figure, will be updated and displayed before the pause (show data ploting live/animation)
else:
num = int(num*3+1) #if number is odd make it even
iterations += 1
List_number.append(num) # Add number value in list, every time
List_iteration.append(iterations) #iteration
plt.plot(List_iteration, List_number , 'b-o')
plt.pause(0.0001)
if(num == 1): #Next number !
print(' Number : ',number, ', Iterations : ',iterations, ', True ', '\n' )
number += 1 #increment
iterations=0
num = number
List_iteration=[0] # reset/empty lists for next round
List_number=[0]
elif(num == 0): # conjecture break , alert !
print(' Number : ', number, ', False ', '\n' )
plt.show() # show ploted graph
break #exit loop