0

I'm trying to use the following code to update my plot every 10 seconds:

@sched.interval_schedule(seconds = 10)
def update_line():

    c = 0
    while c <= 9:
        y[c] = y[c] + 1
        c = c+1

    x = range(1, 11)
    plt.ion()
    fig = plt.figure(1)

    ax = fig.add_subplot(111)
    plt.plot(x, y)

It is only plotting the graph for the first set of y data, after which is displays the error: "WARNING:apscheduler.scheduler:Execution of job "update_line (trigger: interval[0:00:10], next run at: 2013-02-06 16:00:42.942079)" skipped: maximum number of running instances reached (1)"

Should i be using draw() in some way instead?

Thanks

Francesco Montesano
  • 8,485
  • 2
  • 40
  • 64

2 Answers2

0

First the call to plt.ion() and figure creation should be done outside the function/loop where you update the plot itself, as i) when interactivity is on, is on and ii) you don't want a new figure every time.

Give a look at this question and answers. I think that you want to achieve something similar

Community
  • 1
  • 1
Francesco Montesano
  • 8,485
  • 2
  • 40
  • 64
0

First thing is that you keep on adding subplots, while you rather wnat to set the subplot as current axes. To set the output stream to the current subplot use:

plt.figure(1)
plt.subplot(111)

When you only have one subplot (111), the latter is not needed. When you add children to the axes (the subplot) or change them, the figure does not redraw automatically. Add a line

fig.canvas.draw()
Schuh
  • 1,045
  • 5
  • 9