Problem in real time matplotlib plotting

0 votes

Here, In my code x axis='Time' and y='Random Number'. so, I just want to plot graph with these variables using real time matplotlib.

import matplotlib.pyplot as plt
import datetime
import numpy as np
import time

def GetRandomIntNumber(Data):
   timerCounter=0
   x=[]
   y=[]
   while timerCounter < 5000:
       NewNumber = Data * np.random.randomint(5)
       x.append(datetime.datetime.now())
       y.append(NewNumber)
       plt.plot(x,y)
       plt.show()
       time.sleep(10)

a = 10
GetRandomIntNumber(a)
May 24 in Python by Sucheta
109 views

1 answer to this question.

0 votes

Hi Sucheta,

The error I can see in your code that is because there is no function called randomint .

You can check out this code to remove your error.

import matplotlib.pyplot as plt
import datetime
import numpy as np
import time

def GetRandomIntNumber(Data):
   timerCounter=0
   x=[]
   y=[]
   while timerCounter < 5000:
       NewNumber = Data * np.random.randint(5)
       x.append(datetime.datetime.now())
       y.append(NewNumber)
       plt.plot(x,y)
       plt.show()
       time.sleep(10)

a = 10
GetRandomIntNumber(a)

I hope it will help you, just let me know if it works.

answered May 24 by sampriti
• 1,100 points

Related Questions In Python

0 votes
1 answer

Create time lag in Python

import time time.sleep(10) READ MORE

answered May 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
263 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
91 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
56 views
0 votes
1 answer

Get the Current time in Python

To get the current date and time ...READ MORE

answered Oct 3, 2018 in Python by SDeb
• 13,210 points
59 views
0 votes
1 answer

Time delay in Python

The following code will delay it for ...READ MORE

answered Oct 4, 2018 in Python by SDeb
• 13,210 points
109 views
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,960 points
156 views
+1 vote
1 answer

How to handle Real-Time Matplotlib Plotting

To draw a continuous set of random ...READ MORE

answered Sep 26, 2018 in Python by Priyaj
• 56,960 points
3,871 views
0 votes
1 answer

How to increase plt.title font size?

Try the following : import matplotlib.pyplot as plt plt.figtext(.5,.9,'Temperature', ...READ MORE

answered Feb 11 in Python by SDeb
• 13,210 points
143 views
0 votes
1 answer

How to drop missing value in python data-frame?

Hi Sarada,  I understand you are having problems with ...READ MORE

answered May 27 in Python by sampriti
• 1,100 points
64 views