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;








1















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










share|improve this question
























  • 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):. 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

















1















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










share|improve this question
























  • 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):. 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













1












1








1








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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):. 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

















  • 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):. 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
















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












2 Answers
2






active

oldest

votes


















0














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





share|improve this answer























  • 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











  • 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


















0














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()





share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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





    share|improve this answer























    • 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











    • 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















    0














    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





    share|improve this answer























    • 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











    • 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













    0












    0








    0







    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





    share|improve this answer













    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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 22 at 8:41









    consttconstt

    5941811




    5941811












    • 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











    • 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












    • 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













    0














    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()





    share|improve this answer



























      0














      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()





      share|improve this answer

























        0












        0








        0







        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()





        share|improve this answer













        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()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 8 at 10:33









        Keyur KariyaKeyur Kariya

        178




        178



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현