Created
August 6, 2021 04:06
-
-
Save InputBlackBoxOutput/68363f4d8316eff1afec5039798b756e to your computer and use it in GitHub Desktop.
Python program to plot timeseries data stored in a CSV file. Format: <timestamp>,<value>\n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
import matplotlib.pyplot as plt | |
except ModuleNotFoundError: | |
print("Error: Module was not found") | |
sys.exit() | |
except: | |
print("Something went wrong while importing module/s \n") | |
sys.exit() | |
timestamp =[] | |
value = [] | |
inFile = input("Enter file name:") | |
print(f"Reading File {inFile} ......\n") | |
try: | |
with open(f'{inFile}','r') as file_: | |
data = file_.readlines() | |
for each in data: | |
timestamp.append(each.split(",")[0]) | |
value.append((each.split(",")[1]).split("\n")[0]) | |
except FileNotFoundError: | |
print("Error: File Not Found") | |
except: | |
print("Something went wrong while accessing file \n") | |
print("Plotting graph:") | |
print(timestamp, value) | |
if timestamp != [] and value != []: | |
plt.figure() | |
plt.title('Plot') | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
plt.show(plt.plot(timestamp, value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment