Skip to content

Commit a4ec132

Browse files
authored
Merge pull request #1 from Tomy-Niepo/line-plot
Added feature to swtich between lines and dots
2 parents 7835c09 + f978a0a commit a4ec132

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

terminal-plotter.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def parse_args():
5353
help="Path to the data file (default: data.txt)")
5454
parser.add_argument("-i", "--interval", type=float, default=2,
5555
help="Refresh interval in seconds (default: 2)")
56-
# The default for running average window is explicitly set to 5.
5756
parser.add_argument("-a", "--avg-window", type=int, default=5,
5857
help="Window size for running average (default: 5)")
5958
return parser.parse_args()
@@ -63,12 +62,15 @@ def main():
6362
filename = args.file
6463
window_size = args.window
6564
interval = args.interval
66-
avg_window = args.avg_window # This should start as 5 by default.
65+
avg_window = args.avg_window
6766

6867
# Booleans to control visibility of each plotted line.
6968
show_raw = True # Raw data line visible by default.
7069
show_avg = True # Running average line visible by default.
7170

71+
# Plot style control
72+
plot_style = 'dots' # Options: 'dots', 'line'
73+
7274
offset = None
7375
last_max_offset = None
7476

@@ -136,6 +138,10 @@ def main():
136138
elif key == '2':
137139
show_avg = not show_avg
138140
update_plot = True
141+
# Toggle plot style
142+
elif key == 's':
143+
plot_style = 'line' if plot_style == 'dots' else 'dots'
144+
update_plot = True
139145
elif key == 'q':
140146
break
141147

@@ -160,17 +166,25 @@ def main():
160166
plt.xlabel("Index")
161167
plt.ylabel("Value")
162168

163-
# Plot each line only if its toggle is active.
169+
# Plotting with configurable style
164170
if show_raw:
165-
plt.plot(x_vals, window_data, marker="dot", color="cyan", label="Data")
171+
if plot_style == 'dots':
172+
plt.plot(x_vals, window_data, marker="dot", color="cyan", label="Data")
173+
else:
174+
plt.plot(x_vals, window_data, color="cyan", label="Data")
166175
if show_avg:
167-
plt.plot(x_vals, running_avg, marker="dot", color="red",
168-
label=f"Running Avg (window: {avg_window})")
176+
if plot_style == 'dots':
177+
plt.plot(x_vals, running_avg, marker="dot", color="red",
178+
label=f"Running Avg (window: {avg_window})")
179+
else:
180+
plt.plot(x_vals, running_avg, color="red",
181+
label=f"Running Avg (window: {avg_window})")
169182
plt.grid(True)
170183

171184
legend_text = [
172185
f"TW Length: {window_size}",
173186
f"Avg window: {avg_window}",
187+
f"Plot Style: {plot_style}",
174188
f"Data: {'on' if show_raw else 'off'}",
175189
f"Running Avg: {'on' if show_avg else 'off'}"
176190
]
@@ -196,4 +210,3 @@ def main():
196210

197211
if __name__ == "__main__":
198212
main()
199-

0 commit comments

Comments
 (0)