How do I properly plot data extracted from a scope as .csv file
<p>I just extracted a .csv file from a scope, which shows how a signal changes in the time duration of 6 seconds. Problem is that I can't come up with a proper way of plotting this signal, without things getting mushed together.</p>

<p>Mushed together like this:</p>

<p><a href="https://i.stack.imgur.com/XYYa9.png" rel="nofollow"><img src="https://i.stack.imgur.com/XYYa9.png" alt="Matplot screen shoot"></a></p>

<p>The .csv file is <a href="https://ufile.io/12a6" rel="nofollow">here</a>.</p>

<p>The signal goes through four stages, which I want to show with the plot, without it being to mushed together? How do I plot it?</p>

<p>More info about the signal:</p>

<p>The signal is a PWM signal that changes frequency. Either plotting the PWM signal vs. time, or the frequency of the PWM signal vs time, would be plot representation I would be /seeking for. </p>

<p>As a rudimentary analysis, you could do the following using a <code>deque</code> to process a sliding window of values:</p>

<pre><code>from collections import deque
import csv
import matplotlib
import matplotlib.pyplot as plt


maxlen = 20
window = deque(maxlen=maxlen)

with open('12a6-data_extracted_2.csv') as f_input:
    csv_input = csv.reader(f_input, skipinitialspace=True)
    header = next(csv_input)

    freq = []
    x = []

    for v1, v2 in csv_input:
        v1 = float(v1)
        window.append(v1)

        if len(window) == maxlen:
            x.append(v1)
            freq.append(maxlen / ((window[-1] - window[0])))

    plt.plot(x, freq)
    plt.show()
</code></pre>

<p>This would give you an output looking like:</p>

<p><a href="https://i.stack.imgur.com/SmIBH.png" rel="nofollow"><img src="https://i.stack.imgur.com/SmIBH.png" alt="Frequency"></a></p>

python matlab csv plot gnuplot