Last active
July 14, 2024 18:39
-
-
Save kng/232d3e8badb77f1e0946814896ce4323 to your computer and use it in GitHub Desktop.
gr-satellites --dump_path simple plotter
This file contains 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
#!/usr/bin/env python3 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sys import argv | |
def waveform_plot(w): | |
print(f"Plotting {w}") | |
try: | |
x = np.fromfile(w, dtype='float32') | |
except FileNotFoundError: | |
print(f"File {w} not found") | |
return 1 | |
# enabling sharex breaks the histogram scale | |
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10, 6), tight_layout=True, | |
gridspec_kw={'width_ratios': [0.8, 0.2]}) | |
plt.yticks(np.arange(-5, 5, 0.1), minor=True) | |
fig.subplots_adjust(hspace=0, wspace=0) | |
# plot of signal | |
ax1.set_title(w, loc='left') | |
ax1.grid(axis='y', alpha=0.5) | |
ax1.grid(axis='y', which='minor', alpha=0.1) | |
ax1.plot(x, linestyle='-', marker='.', markersize=1.0, linewidth=0.2) | |
# it would be good to be able to show histogram on the zoomed x-range from the plot | |
ax2.tick_params(which='both', labelright=True, left=False, right=True) | |
ax2.grid(axis='y', alpha=0.5) | |
ax2.grid(axis='y', which='minor', alpha=0.1) | |
ax2.hist(x, density=True, bins=500, orientation='horizontal') | |
plt.show() | |
if __name__ == "__main__": | |
if len(argv) > 1: | |
waveform_plot(argv[1]) | |
else: | |
f = "waveform.f32" | |
print(f"Usage: {argv[0]} <{f}>") | |
waveform_plot(f) # try plot with default file | |
if __name__ == "__main__": | |
if len(argv) > 1: | |
waveform_plot(argv[1]) | |
else: | |
f = "waveform.f32" | |
print(f"Usage: {argv[0]} <{f}>") | |
waveform_plot(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment