Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Created August 19, 2018 20:04
Show Gist options
  • Save nikhilkumarsingh/1dcec96a1eb0aeb8975fc13ec5825d43 to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/1dcec96a1eb0aeb8975fc13ec5825d43 to your computer and use it in GitHub Desktop.
Plotting real time data using Python
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CriptoEdo
Copy link

Hello,

Would you be able to replicate this code in Spyder?

You cannot call "%matplotlib notebook" in Spyder. I set up the Graphics backend of the Iphyton console in "Automatic", but the plot windows doesn't answer until I stop the program and it returns me the "final graph" (after some iterations).

@PALANIVELAADHI
Copy link

fine

@abdxd007
Copy link

how to write the same code in R language?

@Kennerdol
Copy link

can you help me to embed the plot on Tkinter GUI and use a function?

from tkinter import *
import psutil
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.figure import Figure
import time

def graphing():
    i = 0
    x, y = [], []

    while True:
        x.append(i)
        y.append(psutil.cpu_percent())
        ax.plot(x, y, color='b')
        fig.canvas.draw()
        ax.set_xlim(left=max(0, i-50), right=i+50)
        time.sleep(0.1)
        i += 1


# ====================================Main GUI=====================================
main_window = Tk()
main_window.title("REAL TIME DATA")
main_window.configure(background='light blue')
main_window.geometry('500x500')
main_window.resizable(width=False, height=False)

plt.close('all')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title("Electrocadiogram")
ax.set_xlabel("Time(Sec)")
ax.set_ylabel("Voltage(mV)")
canvas = FigureCanvasTkAgg(fig, master=main_window)
canvas.get_tk_widget().place(x =10, y = 10, width = 500, height = 400)
canvas.draw()

start_button = Button(bottom_Lframe, text='Exit', width=8, height=2, borderwidth=3, command=graphing)
start_button.pack()


main_window.mainloop()

@Gemco1
Copy link

Gemco1 commented Feb 19, 2022

is it possible to replicate this code but in 3D plane instead of 2D ?

@mubangansofu
Copy link

how to write the same code in R language?

You can use the reticulate package and write the code in python directly in R or RMarkdown

@marwanco62
Copy link

Hello,

Would you be able to replicate this code in Spyder?

You cannot call "%matplotlib notebook" in Spyder. I set up the Graphics backend of the Iphyton console in "Automatic", but the plot windows doesn't answer until I stop the program and it returns me the "final graph" (after some iterations).

replace
time.sleep(0.1)
with
plt.pause(0.1)
Works with spyder 5.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment