some things are working but regulation is fucked!
This commit is contained in:
94
plotscript/python_csv_plotter.py
Normal file
94
plotscript/python_csv_plotter.py
Normal file
@@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Spyder Editor
|
||||
|
||||
This is a temporary script file.
|
||||
"""
|
||||
import sys
|
||||
import matplotlib.pyplot as plt
|
||||
import csv
|
||||
import numpy as np
|
||||
|
||||
|
||||
|
||||
# Initialize arrays
|
||||
time_array = []
|
||||
temperature_array = []
|
||||
power_array = []
|
||||
fan_speed_array = []
|
||||
|
||||
temperature_end_offset = 10 # Optional, adjust as needed
|
||||
|
||||
with open(sys.argv[1], newline='') as csvfile:
|
||||
datareader = csv.reader(csvfile, delimiter=',', quotechar='|')
|
||||
|
||||
for count, row in enumerate(datareader):
|
||||
if count == 0:
|
||||
# Labels row
|
||||
time_name = row[0]
|
||||
temp_name = row[1]
|
||||
power_name = row[2]
|
||||
plot_title = row[3]
|
||||
#fan_speed_name = row[4] # Assuming fan speed is at index 5
|
||||
else:
|
||||
time_array.append(float(row[0]))
|
||||
temperature_array.append(float(row[1]))
|
||||
power_array.append(float(row[2]))
|
||||
fan_speed_array.append(float(row[3]))
|
||||
|
||||
# Track min/max for scaling
|
||||
if count == 1:
|
||||
min_temp = float(row[1])
|
||||
max_temp = float(row[1])
|
||||
else:
|
||||
temp_val = float(row[1])
|
||||
if temp_val > max_temp:
|
||||
max_temp = temp_val
|
||||
if temp_val < min_temp:
|
||||
min_temp = temp_val
|
||||
|
||||
# Begin plotting
|
||||
fig1, ax1 = plt.subplots()
|
||||
fig1.canvas.manager.set_window_title('DVT-Light Python Plotter V1.1')
|
||||
fig1.suptitle(plot_title)
|
||||
|
||||
# Plot Vout
|
||||
color = 'tab:blue'
|
||||
ax1.set_xlabel('time (s)')
|
||||
ax1.set_ylabel('Vout', color=color)
|
||||
ax1.plot(time_array, temperature_array, color=color, label='Vout')
|
||||
ax1.tick_params(axis='y', labelcolor=color)
|
||||
ax1.set_ylim(min_temp, max_temp + temperature_end_offset)
|
||||
ax1.set_yticks(np.arange(min_temp, max_temp + temperature_end_offset, step=10))
|
||||
ax1.grid(True)
|
||||
|
||||
# Plot Power (2nd y-axis)
|
||||
ax2 = ax1.twinx()
|
||||
color = 'tab:red'
|
||||
ax2.set_ylabel('Current', color=color)
|
||||
ax2.plot(time_array, power_array, color=color, label='Current')
|
||||
ax2.tick_params(axis='y', labelcolor=color)
|
||||
|
||||
# Plot Duty (3rd y-axis)
|
||||
ax3 = ax1.twinx()
|
||||
color = 'tab:purple'
|
||||
ax3.spines["right"].set_position(("axes", 1.15)) # Offset 3rd y-axis
|
||||
ax3.set_frame_on(True)
|
||||
ax3.patch.set_visible(False)
|
||||
for sp in ax3.spines.values():
|
||||
sp.set_visible(False)
|
||||
ax3.spines["right"].set_visible(True)
|
||||
|
||||
ax3.set_ylabel('Duty', color=color)
|
||||
ax3.plot(time_array, fan_speed_array, color=color, linestyle=':', label='Duty')
|
||||
ax3.tick_params(axis='y', labelcolor=color)
|
||||
|
||||
# Combine legends
|
||||
lines, labels = ax1.get_legend_handles_labels()
|
||||
lines2, labels2 = ax2.get_legend_handles_labels()
|
||||
lines3, labels3 = ax3.get_legend_handles_labels()
|
||||
ax1.legend(lines + lines2 + lines3, labels + labels2 + labels3, loc='upper left')
|
||||
|
||||
fig1.tight_layout()
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user