0

I'm new in matplotlib. I want to update a data in an endless while loop in a different thread in addition to updating the plot in the pyplot.show method. I tried using the threading import but it isn't working well together with pyplot.show method. I know I can use pyplot.ion and it works fine with the threads. The problem with pyplot.ion is that it is not efficient. Is there any way that i could use pyplot.show instead?

To make myself clear, I don't want the solution:

    pyplot.ion()
    ....
    while True:
    ....
        pyplot.show()
Py566
  • 1
  • 3

2 Answers2

0

I'm not sure if this solves your problem, but you could try to use pyplot.draw()instead of pyplot.show(). If you already have used show() once, will it update the plot? draw() should update the plot though.

I do not know how you plot the data, but assuming that the data-set you're plotting is of the same size every time one trick to speed things up is to use set_data(), if you the first time you plot store the line-artist as

x, y = generate_data_function()
line, = pyplot.plot(x, y)
pyplot.show()

while True:
    x, y = generate_data_function()
    line.set_data(x, y)
    pyplot.draw()

Hope it helps! As I said, I'm not completely sure if it really solves your problem but it could be worth trying at least.

pathoren
  • 1,634
  • 2
  • 14
  • 22
  • Umm, yes this works, but I have already known about this solution " I know I can use pyplot.ion and it works fine with the threads". But I used `pyplot.ion` instead of `pyplot.show`. I think `pyplot.show` won't work, as it will stop at that line. – Py566 Jan 21 '14 at 18:04
0

I have found gobject.idle_add() and gobject.threads_init() to be very useful. It was almost exactly what I needed. I also found these resources useful: Can you plot live data in matplotlib? http://wiki.scipy.org/Cookbook/Matplotlib/Animations

Community
  • 1
  • 1
Py566
  • 1
  • 3