A technician runs the following script once in an initially empty output directory. Every save succeeds, and saving to an existing filename replaces that file. Each ax.plot call here adds one data-line object. Count these objects even if their drawings overlap; do not count coordinate-axis lines.
import matplotlib.pyplot as plt time_s = [0, 1, 2, 3] runs_v = [ [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], ] fig, ax = plt.subplots() for readings_v in runs_v: ax.plot(time_s, readings_v) fig.savefig("trials.png") ax.clear() ax.plot(time_s, [4, 4, 4, 4]) fig.savefig("restart.png") ax.plot(time_s, [6, 6, 6, 6])
Times are in seconds and readings are in volts. After the entire script finishes, report four exact integer counts: the number of PNG files in the directory, the number of data-line objects represented in trials.png, the number represented in restart.png, and the number remaining on the live ax object.
Unlock full course notes by signing up
Read a value between plotted samples
A sensor records voltage at three elapsed times. The following Matplotlib call produces the illustrated line plot, with straight connecting segments and linear scales on both axes.
What voltage does the displayed segment have at an elapsed time of 7 s7\ \text{s}7 s? Answer in volts, to one decimal place. Find the plotted height, rather than claiming an additional sensor measurement.
Diagnose missing horizontal coordinates
A cart's distance is recorded at unevenly spaced elapsed times. A student intends to plot elapsed time horizontally and distance vertically but writes the one-argument plotting call below. The plotting area ax already exists.
Which statements correctly describe the current call or the proposed replacements? Select every true statement.
Target the correct figure when saving and closing
An engineer creates separate graphics for a sensor run and a calibration check. Assume both figures remain open after this code executes.
The horizontal values are times in seconds, and the vertical values are voltages in volts. Complete the instructions using variable names from the code.
To save only the sensor-run graphic, put ________ before .savefig("sensor_run.png").
Explain the consequence of independent sorting
A data file contains corresponding sensor measurements in an order that is not chronological. Two programs attempt to draw voltage against increasing elapsed time.
In the code, zip groups corresponding times and voltages. Sorting the resulting pairs orders them by time, and zip(*pairs) separates the sorted pairs back into coordinate sequences. Both plotting areas already exist and use linear scales with straight connecting segments.
At t=3 st=3\ \text{s}t=3 s, determine the displayed voltage in each plot: the plot made by sorting pairs together and the plot made by sorting the lists separately. Answer both in volts, to one decimal place.