Live scatter plot fetching data from firebase every 2 second The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceMatplotlib plots not showing up in Mac OSX?How to do a scatter plot with empty circles in Python?How to put individual tags for a scatter plotSetting different color for each series in scatter plot on matplotlibmatplotlib scatter plot with different text at each data pointpyplot scatter plot marker sizeMatplotlib scatter plot legendUpdate colour of plot in 3d matplotlibPython modules to plot game of life scriptAdding second legend to scatter plotWhat is the best way to animate series of 2D arrays as scatter plots?
Make it rain characters
Are my PIs rude or am I just being too sensitive?
Derivation tree not rendering
What information about me do stores get via my credit card?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
How long does the line of fire that you can create as an action using the Investiture of Flame spell last?
does high air pressure throw off wheel balance?
Cooking pasta in a water boiler
Sort a list of pairs representing an acyclic, partial automorphism
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
What is this lever in Argentinian toilets?
Did God make two great lights or did He make the great light two?
Take groceries in checked luggage
Why did all the guest students take carriages to the Yule Ball?
Reference for the teaching of not-self
How do I add random spotting to the same face in cycles?
Does Parliament hold absolute power in the UK?
In horse breeding, what is the female equivalent of putting a horse out "to stud"?
Why can't devices on different VLANs, but on the same subnet, communicate?
Is this wall load bearing? Blueprints and photos attached
University's motivation for having tenure-track positions
Why can't wing-mounted spoilers be used to steepen approaches?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
Mortgage adviser recommends a longer term than necessary combined with overpayments
Live scatter plot fetching data from firebase every 2 second
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceMatplotlib plots not showing up in Mac OSX?How to do a scatter plot with empty circles in Python?How to put individual tags for a scatter plotSetting different color for each series in scatter plot on matplotlibmatplotlib scatter plot with different text at each data pointpyplot scatter plot marker sizeMatplotlib scatter plot legendUpdate colour of plot in 3d matplotlibPython modules to plot game of life scriptAdding second legend to scatter plotWhat is the best way to animate series of 2D arrays as scatter plots?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a mobile application which does some calculation and throws x,y coordinates and are updated on firebase every 2 seconds.
Next i want those coordinates to be plotted on a floor plan live. For that i am using Scatter plot over the floor plan image. But i cannot make it live as soon as the data is fetched need help with that.
Here is the code till now:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
xs = []
ys = []
fig = plt.figure()
scat = plt.scatter(xs, ys, c='r', s=100)
def main():
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
x,y = line.split(",")
xs.append(x)
ys.append(y)
plt.scatter(xs,ys)
print(xs)
print(ys)
ani = animation.FuncAnimation(fig,main(),fargs=(scat))
plt.show()
Getting error with animation.FuncAnimation
TypeError: NoneType object argument after * must be an iterable, not PathCollection
python firebase matplotlib scatter-plot
add a comment |
I have a mobile application which does some calculation and throws x,y coordinates and are updated on firebase every 2 seconds.
Next i want those coordinates to be plotted on a floor plan live. For that i am using Scatter plot over the floor plan image. But i cannot make it live as soon as the data is fetched need help with that.
Here is the code till now:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
xs = []
ys = []
fig = plt.figure()
scat = plt.scatter(xs, ys, c='r', s=100)
def main():
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
x,y = line.split(",")
xs.append(x)
ys.append(y)
plt.scatter(xs,ys)
print(xs)
print(ys)
ani = animation.FuncAnimation(fig,main(),fargs=(scat))
plt.show()
Getting error with animation.FuncAnimation
TypeError: NoneType object argument after * must be an iterable, not PathCollection
python firebase matplotlib scatter-plot
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
1
Have updated the code, Just need help with the animation function, getting this error.TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
The updating function needs to take an argument.def main(i):
. TheFuncAnimation
needs to take this function as argument, not the return.ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.
– ImportanceOfBeingErnest
Mar 22 at 12:46
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53
add a comment |
I have a mobile application which does some calculation and throws x,y coordinates and are updated on firebase every 2 seconds.
Next i want those coordinates to be plotted on a floor plan live. For that i am using Scatter plot over the floor plan image. But i cannot make it live as soon as the data is fetched need help with that.
Here is the code till now:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
xs = []
ys = []
fig = plt.figure()
scat = plt.scatter(xs, ys, c='r', s=100)
def main():
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
x,y = line.split(",")
xs.append(x)
ys.append(y)
plt.scatter(xs,ys)
print(xs)
print(ys)
ani = animation.FuncAnimation(fig,main(),fargs=(scat))
plt.show()
Getting error with animation.FuncAnimation
TypeError: NoneType object argument after * must be an iterable, not PathCollection
python firebase matplotlib scatter-plot
I have a mobile application which does some calculation and throws x,y coordinates and are updated on firebase every 2 seconds.
Next i want those coordinates to be plotted on a floor plan live. For that i am using Scatter plot over the floor plan image. But i cannot make it live as soon as the data is fetched need help with that.
Here is the code till now:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
xs = []
ys = []
fig = plt.figure()
scat = plt.scatter(xs, ys, c='r', s=100)
def main():
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
x,y = line.split(",")
xs.append(x)
ys.append(y)
plt.scatter(xs,ys)
print(xs)
print(ys)
ani = animation.FuncAnimation(fig,main(),fargs=(scat))
plt.show()
Getting error with animation.FuncAnimation
TypeError: NoneType object argument after * must be an iterable, not PathCollection
python firebase matplotlib scatter-plot
python firebase matplotlib scatter-plot
edited Mar 22 at 7:37
Keyur Kariya
asked Mar 22 at 6:49
Keyur KariyaKeyur Kariya
178
178
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
1
Have updated the code, Just need help with the animation function, getting this error.TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
The updating function needs to take an argument.def main(i):
. TheFuncAnimation
needs to take this function as argument, not the return.ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.
– ImportanceOfBeingErnest
Mar 22 at 12:46
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53
add a comment |
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
1
Have updated the code, Just need help with the animation function, getting this error.TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
The updating function needs to take an argument.def main(i):
. TheFuncAnimation
needs to take this function as argument, not the return.ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.
– ImportanceOfBeingErnest
Mar 22 at 12:46
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
1
1
Have updated the code, Just need help with the animation function, getting this error.
TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
Have updated the code, Just need help with the animation function, getting this error.
TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
The updating function needs to take an argument.
def main(i):
. The FuncAnimation
needs to take this function as argument, not the return. ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.– ImportanceOfBeingErnest
Mar 22 at 12:46
The updating function needs to take an argument.
def main(i):
. The FuncAnimation
needs to take this function as argument, not the return. ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.– ImportanceOfBeingErnest
Mar 22 at 12:46
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53
add a comment |
2 Answers
2
active
oldest
votes
You can fetch data in a separate thread while updating the plot in the main one. Here is a complete working example:
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread, Event
import numpy as np
import matplotlib.pyplot as plt
FETCH_DELAY = 2
def fetch_data(queue, stop):
while not stop.is_set():
x, y = np.random.randn(2)
queue.put((x, y))
time.sleep(FETCH_DELAY)
def limits(array, offset=1):
return array.min() - offset, array.max() + offset
def main():
stop = Event()
queue = Queue()
worker = Thread(target=fetch_data, args=(queue, stop))
worker.start()
plt.ion()
fig, ax = plt.subplots()
plot = ax.scatter([], [])
try:
while True:
data = queue.get()
data = np.array(data)
plt_data = plot.get_offsets()
plt_data = np.vstack((plt_data, data))
plot.set_offsets(plt_data)
fig.canvas.draw()
xmin, xmax = limits(plt_data[:, 0])
ymin, ymax = limits(plt_data[:, 1])
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
queue.task_done()
except KeyboardInterrupt:
pass
finally:
stop.set()
worker.join()
if __name__ == '__main__':
main()
Save it as plot_update.py
file and run it from the command line:
python3 plot_update.py
Followed this Save it asplot_update.py
file and run it from the command line:python3 plot_update.py
shows no output
– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
add a comment |
Here is the solution without using threads it becomes very simple:
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from firebase import firebase
firebase = firebase.FirebaseApplication('Firebase url', None)
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y,c=np.random.rand(3,))
plt.xlim(12,13)
plt.ylim(77,78)
def animate(i):
xs = firebase.get('/Lat',None)
ys = firebase.get('/Long',None)
xs = round(xs,2)
ys = round(ys,2)
file = open("testfile.txt","a+")
file.write("0,1 n".format(xs,ys))
file.close()
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
xs,ys = line.split(",")
x.append(xs)
y.append(ys)
sc.set_offsets(np.c_[x,y])
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=500, repeat=True)
plt.show()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294269%2flive-scatter-plot-fetching-data-from-firebase-every-2-second%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can fetch data in a separate thread while updating the plot in the main one. Here is a complete working example:
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread, Event
import numpy as np
import matplotlib.pyplot as plt
FETCH_DELAY = 2
def fetch_data(queue, stop):
while not stop.is_set():
x, y = np.random.randn(2)
queue.put((x, y))
time.sleep(FETCH_DELAY)
def limits(array, offset=1):
return array.min() - offset, array.max() + offset
def main():
stop = Event()
queue = Queue()
worker = Thread(target=fetch_data, args=(queue, stop))
worker.start()
plt.ion()
fig, ax = plt.subplots()
plot = ax.scatter([], [])
try:
while True:
data = queue.get()
data = np.array(data)
plt_data = plot.get_offsets()
plt_data = np.vstack((plt_data, data))
plot.set_offsets(plt_data)
fig.canvas.draw()
xmin, xmax = limits(plt_data[:, 0])
ymin, ymax = limits(plt_data[:, 1])
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
queue.task_done()
except KeyboardInterrupt:
pass
finally:
stop.set()
worker.join()
if __name__ == '__main__':
main()
Save it as plot_update.py
file and run it from the command line:
python3 plot_update.py
Followed this Save it asplot_update.py
file and run it from the command line:python3 plot_update.py
shows no output
– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
add a comment |
You can fetch data in a separate thread while updating the plot in the main one. Here is a complete working example:
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread, Event
import numpy as np
import matplotlib.pyplot as plt
FETCH_DELAY = 2
def fetch_data(queue, stop):
while not stop.is_set():
x, y = np.random.randn(2)
queue.put((x, y))
time.sleep(FETCH_DELAY)
def limits(array, offset=1):
return array.min() - offset, array.max() + offset
def main():
stop = Event()
queue = Queue()
worker = Thread(target=fetch_data, args=(queue, stop))
worker.start()
plt.ion()
fig, ax = plt.subplots()
plot = ax.scatter([], [])
try:
while True:
data = queue.get()
data = np.array(data)
plt_data = plot.get_offsets()
plt_data = np.vstack((plt_data, data))
plot.set_offsets(plt_data)
fig.canvas.draw()
xmin, xmax = limits(plt_data[:, 0])
ymin, ymax = limits(plt_data[:, 1])
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
queue.task_done()
except KeyboardInterrupt:
pass
finally:
stop.set()
worker.join()
if __name__ == '__main__':
main()
Save it as plot_update.py
file and run it from the command line:
python3 plot_update.py
Followed this Save it asplot_update.py
file and run it from the command line:python3 plot_update.py
shows no output
– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
add a comment |
You can fetch data in a separate thread while updating the plot in the main one. Here is a complete working example:
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread, Event
import numpy as np
import matplotlib.pyplot as plt
FETCH_DELAY = 2
def fetch_data(queue, stop):
while not stop.is_set():
x, y = np.random.randn(2)
queue.put((x, y))
time.sleep(FETCH_DELAY)
def limits(array, offset=1):
return array.min() - offset, array.max() + offset
def main():
stop = Event()
queue = Queue()
worker = Thread(target=fetch_data, args=(queue, stop))
worker.start()
plt.ion()
fig, ax = plt.subplots()
plot = ax.scatter([], [])
try:
while True:
data = queue.get()
data = np.array(data)
plt_data = plot.get_offsets()
plt_data = np.vstack((plt_data, data))
plot.set_offsets(plt_data)
fig.canvas.draw()
xmin, xmax = limits(plt_data[:, 0])
ymin, ymax = limits(plt_data[:, 1])
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
queue.task_done()
except KeyboardInterrupt:
pass
finally:
stop.set()
worker.join()
if __name__ == '__main__':
main()
Save it as plot_update.py
file and run it from the command line:
python3 plot_update.py
You can fetch data in a separate thread while updating the plot in the main one. Here is a complete working example:
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread, Event
import numpy as np
import matplotlib.pyplot as plt
FETCH_DELAY = 2
def fetch_data(queue, stop):
while not stop.is_set():
x, y = np.random.randn(2)
queue.put((x, y))
time.sleep(FETCH_DELAY)
def limits(array, offset=1):
return array.min() - offset, array.max() + offset
def main():
stop = Event()
queue = Queue()
worker = Thread(target=fetch_data, args=(queue, stop))
worker.start()
plt.ion()
fig, ax = plt.subplots()
plot = ax.scatter([], [])
try:
while True:
data = queue.get()
data = np.array(data)
plt_data = plot.get_offsets()
plt_data = np.vstack((plt_data, data))
plot.set_offsets(plt_data)
fig.canvas.draw()
xmin, xmax = limits(plt_data[:, 0])
ymin, ymax = limits(plt_data[:, 1])
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
queue.task_done()
except KeyboardInterrupt:
pass
finally:
stop.set()
worker.join()
if __name__ == '__main__':
main()
Save it as plot_update.py
file and run it from the command line:
python3 plot_update.py
answered Mar 22 at 8:41
consttconstt
5941811
5941811
Followed this Save it asplot_update.py
file and run it from the command line:python3 plot_update.py
shows no output
– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
add a comment |
Followed this Save it asplot_update.py
file and run it from the command line:python3 plot_update.py
shows no output
– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
Followed this Save it as
plot_update.py
file and run it from the command line: python3 plot_update.py
shows no output– Keyur Kariya
Mar 22 at 9:14
Followed this Save it as
plot_update.py
file and run it from the command line: python3 plot_update.py
shows no output– Keyur Kariya
Mar 22 at 9:14
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
For me, it works like a charm: Ubuntu 16.04.6 LTS, Python 3.5.2. Any error messages?
– constt
Mar 22 at 9:41
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
No Error Message, and no output, i am using Mac Os Mojave, and Python 3.7
– Keyur Kariya
Mar 22 at 9:55
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
This might help stackoverflow.com/a/2512358/3920623
– constt
Mar 22 at 10:43
add a comment |
Here is the solution without using threads it becomes very simple:
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from firebase import firebase
firebase = firebase.FirebaseApplication('Firebase url', None)
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y,c=np.random.rand(3,))
plt.xlim(12,13)
plt.ylim(77,78)
def animate(i):
xs = firebase.get('/Lat',None)
ys = firebase.get('/Long',None)
xs = round(xs,2)
ys = round(ys,2)
file = open("testfile.txt","a+")
file.write("0,1 n".format(xs,ys))
file.close()
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
xs,ys = line.split(",")
x.append(xs)
y.append(ys)
sc.set_offsets(np.c_[x,y])
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=500, repeat=True)
plt.show()
add a comment |
Here is the solution without using threads it becomes very simple:
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from firebase import firebase
firebase = firebase.FirebaseApplication('Firebase url', None)
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y,c=np.random.rand(3,))
plt.xlim(12,13)
plt.ylim(77,78)
def animate(i):
xs = firebase.get('/Lat',None)
ys = firebase.get('/Long',None)
xs = round(xs,2)
ys = round(ys,2)
file = open("testfile.txt","a+")
file.write("0,1 n".format(xs,ys))
file.close()
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
xs,ys = line.split(",")
x.append(xs)
y.append(ys)
sc.set_offsets(np.c_[x,y])
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=500, repeat=True)
plt.show()
add a comment |
Here is the solution without using threads it becomes very simple:
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from firebase import firebase
firebase = firebase.FirebaseApplication('Firebase url', None)
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y,c=np.random.rand(3,))
plt.xlim(12,13)
plt.ylim(77,78)
def animate(i):
xs = firebase.get('/Lat',None)
ys = firebase.get('/Long',None)
xs = round(xs,2)
ys = round(ys,2)
file = open("testfile.txt","a+")
file.write("0,1 n".format(xs,ys))
file.close()
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
xs,ys = line.split(",")
x.append(xs)
y.append(ys)
sc.set_offsets(np.c_[x,y])
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=500, repeat=True)
plt.show()
Here is the solution without using threads it becomes very simple:
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from firebase import firebase
firebase = firebase.FirebaseApplication('Firebase url', None)
fig, ax = plt.subplots()
x, y = [],[]
sc = ax.scatter(x,y,c=np.random.rand(3,))
plt.xlim(12,13)
plt.ylim(77,78)
def animate(i):
xs = firebase.get('/Lat',None)
ys = firebase.get('/Long',None)
xs = round(xs,2)
ys = round(ys,2)
file = open("testfile.txt","a+")
file.write("0,1 n".format(xs,ys))
file.close()
graph_data = open("testfile.txt","r").read()
lines = graph_data.split("n")
for line in lines:
if len(line)>1:
xs,ys = line.split(",")
x.append(xs)
y.append(ys)
sc.set_offsets(np.c_[x,y])
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=500, repeat=True)
plt.show()
answered Apr 8 at 10:33
Keyur KariyaKeyur Kariya
178
178
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294269%2flive-scatter-plot-fetching-data-from-firebase-every-2-second%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please fix your indentation.
– Thomas Kühn
Mar 22 at 7:20
1
Have updated the code, Just need help with the animation function, getting this error.
TypeError: update_plot() argument after * must be an iterable, not PathCollection
– Keyur Kariya
Mar 22 at 7:22
The updating function needs to take an argument.
def main(i):
. TheFuncAnimation
needs to take this function as argument, not the return.ani = animation.FuncAnimation(fig,main)
. This is to get rid of the error; the code will soon enough slow down, because you create a new scatter in each frame. Google for "matplotlib update scatter" for more efficient solutions.– ImportanceOfBeingErnest
Mar 22 at 12:46
Yes this works just fine. Thanks.
– Keyur Kariya
Mar 26 at 8:53