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.


Python
time_s = [6, 0, 2]
voltage_v = [12, 10, 18]

pairs = sorted(zip(time_s, voltage_v))
t_paired, v_paired = zip(*pairs)
ax_paired.plot(t_paired, v_paired)

ax_separate.plot(sorted(time_s), sorted(voltage_v))


At t=3 st=3\ \text{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.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Matplotlib Questions: