A4 Python for engineers · Practice
Plotting signals with matplotlib
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
Plot a capacitor's discharge, with = 1 ms, from 0 to , with time in milliseconds on the x axis. Label both axes and mark with a dashed vertical line.
V0 = 6 (volts) and tau = 1 (milliseconds) are already defined.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On one set of axes, plot and over 40 ms, with time in ms, and add a legend naming them v1 and v2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has ten measured points, voltages V and currents I in amps, from a resistor of about 2200 Ω. Plot the points as dots with no line joining them ('o'), then the straight line through them as a solid line over the same voltages. Label both axes with units.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the output of a bits-bit ADC (3 bits, so codes 0 to 2**bits - 1, full scale 1 V) for an input ramp vin from 0 to 1 V over 1 ms, as a staircase: use plt.step(t_ms, code, where='post'), where code is np.floor(vin * 2**bits) clipped to the top code. Label both axes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the charging curve , = 1 ms, from 0 to ms, and draw a dashed horizontal line at 4 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a Bode magnitude plot in dB of from 10 Hz to 1 MHz, with a log frequency axis. Store the dB values in mag_db.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4