# Plotting Graph on matplotlib under while loop- graph not plotting

Hello guys, I have been into python for just couple of months and I wanted to plot the graph from the output of arithmetic (These arithmetic program works fine for me). When I try to incorporate matplotlib to while loop for plotting data, I am not getting any graph.

Working Arithmetic code:

``````n=int(input("Enter the Number "))
count=0
a=0
a=n
while(n!=1):
if(n%2==0):
n=n//2
print(str(n)+ '\n')
count=count+1
else:
n=3*n+1
print(str(n)+'\n')
count=count+1
print("Collatz for "+ str(a) + " count is " + str(count))
``````

Graph Plotting code (I am not getting desired output)

``````import matplotlib.pyplot as plt
def collatz():
n=int(input("Enter the Number "))
count=0
a=0
a=n
while(n!=1):
if(n%2==0):
n=n//2
print(str(n)+ '\n')
count=count+1
plt.show()
else:
n=3*n+1
print(str(n)+'\n')
count=count+1
x=[count]
y=[n]
plt.plot(x,y)
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.title('My first graph!')
collatz()
``````

Basically if I enter number (say 8) then output will be 8,4,2,1 and these data must be plotted to 1,2,3,4

Something like below: 