I want to stop overlapping graphs.

Asked 2 years ago, Updated 2 years ago, 20 views

I am currently thinking of making measurements every few seconds using python, and I am thinking of following python matplotlib to make a graph.
However, if you write a code like the one below, it will be looped and even the text you read last time will be loaded into the graph, and it will be displayed as the one you want to display.

How can I erase the previous text data and read only the latest text data?
Thank you for your cooperation.

import datetime
import time
importos

from matplotlib import pyplot as plt
import numpy as np

os.mkdir ("test")

oclock = datetime.datetime.today()

while True:

    data=np.loadtxt('exp-data.txt', delimiter=', unpack=True)

    xm = data [:, 0]
    ym=data[:,1]

    x = xm / 1023
    y=ym/1023

    plt.plot(x,y)

    os.chdir("/home/ienaga/desktop/matplot_test/test")
    plt.savefig('sample.png')
    now=datetime.datetime.now()
    newname="{0:%Y-%m-%d-%H:%M:%S}.png".format(now)
    a=os.rename("sample.png", newname)
    os.chdir("/home/ienaga/desktop/matplot_test")

    time.sleep(5)

python

2022-09-30 18:32

1 Answers

Why don't you call plt.figure() in the previous line of np.loadtext()?


2022-09-30 18:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.