0

I have a long data sequence to plot, and am trying to pan along the x axis programmatically.

fig_raw = plt.figure(num = 'raw');  
plt.plot(data_rd, figure=fig_raw);  
plt.xlim(0, 200);  
plt.show(False);  
for i in range(0, data_rd.size/200-1):  
    plt.xlim(i*200, (i+1)*200);  
    time.sleep(1)

But this code does not pan through the x axis. It shows the first xlimits and the final xlimits in x axis. I have tried adding plt.draw() after each call to xlim, but the behaviour is the same. If I add raw_input('any text') after each xlim, the figure's x axis limits are updated.

What works:

fig_raw = plt.figure(num = 'raw');  
plt.plot(data_rd, figure=fig_raw);  
plt.xlim(0, 200);  
plt.show(False);  
for i in range(0, data_rd.size/200-1):  
    plt.xlim(i*200, (i+1)*200);  
    plt.draw();
    raw_input(i);
    time.sleep(1);  

How can I do programmatic pan (without using raw_input())?

Priya
  • 334
  • 3
  • 8
  • If you want to use a loop, you need to activate interactive mode via `plt.ion()`. This is shown in the duplicate. Alternatively I would recommend using `FuncAnimation` which is much more stable. There are many possible answers using `FuncAnimation` on this site. – ImportanceOfBeingErnest Jul 11 '18 at 18:39

1 Answers1

0

Try to change the dimensions of the graph

fig = plt.figure(figsize=(20, 2))
ax = fig.add_subplot(111)
ax.plot(x, y)

as mentioned in answer to this question

Farbod Shahinfar
  • 777
  • 6
  • 15