Last active
February 11, 2020 17:50
-
-
Save RyanFleck/54f598f07a04e9719ed5a84344edd1cc to your computer and use it in GitHub Desktop.
For a set of *.csv files, return *.png graphs of the first and third columns with different colors.
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 numpy as np | |
import matplotlib.pyplot as plt | |
import csv | |
import glob | |
import os | |
print("Gathering CSVs...") | |
csvFiles = sorted(glob.glob(os.getcwd() + "/*.csv")) | |
numpyFileData = [] | |
iteration = 1 | |
voltage = 1 | |
colors = ['red', 'green', 'blue', 'orange', 'purple'] | |
for x in csvFiles: | |
print("Found " + x) | |
filename = os.path.splitext(os.path.basename(x))[0] | |
saveto = "{}.png".format(filename) | |
# .csv files from ELG3155 labs have the following columns: | |
# Time (ms) | Raw speed error (mV) | Raw speed (mrad/s) | Reference (mV) | | |
# Control output (mV) | |
ms, SmV, mrad, RmV, CmV = np.loadtxt( | |
x, delimiter=',', skiprows=1, unpack=True) | |
plt.title( | |
"Trial {}: Aux Feedback at Input Amplitude {} V".format( | |
iteration, voltage)) | |
plt.plot(ms, mrad, color=colors[((iteration - 1) % len(colors))]) | |
plt.xlabel('Time (ms)') | |
plt.ylabel('Raw speed (mrad/s)') | |
print("Saving graph to {}".format(saveto)) | |
plt.savefig(saveto, bbox_inches='tight') | |
plt.clf() | |
voltage = voltage + 0.5 | |
iteration = iteration + 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment