0

I am using a python-script to plot voltage that I am monitoring with my RaPi. The relevant code looks like this:

while True:
    y=readChannel(0)
    plt.axis([0, 100, -10, 10])
    plt.ion()                      #plot interactively
    plt.scatter(x, y)
    plt.pause(0.05)              #for the plot not to freeze
    time.sleep(1)
    x += 1

The live-plotting works just fine but I also want the program to save the graph that I see every once in a while. I've tried the plt.savefig() command but then my live plot would not run. Does anyone have an idea how to do that?

Any advice would be appreciated =)

Regards Steve

Steve.1990
  • 27
  • 5
  • You can place `plt.ion()` before the cycle, you shouldn't have to set it every time. To save the figure before displaying it you can probably try to use `plt.savefig()` and then ["manually" update the plot](http://stackoverflow.com/questions/4098131/how-to-update-a-plot-in-matplotlib) – berna1111 Nov 30 '16 at 13:24

1 Answers1

0

The show function also resets the plot. Invoke savefig before show.

enrico.bacis
  • 30,497
  • 10
  • 86
  • 115