PY-90

Make Comparable Evidence Figures

  • Medium
  • Comparable Figures
  • Python

Task

Write make_comparable_figure(series, plot_form, x_label, y_label, comparison). series is a non-empty list of records with exactly three keys: label, x, and y. Labels must be unique, non-empty strings. Convert all numerical values to finite NumPy float64 arrays without changing the inputs.

plot_form is one of "line", "scatter", or "histogram":

  • For a line or scatter figure, each x and y value is one-dimensional, non-empty, and equally long. Draw every series on the same axes in the supplied order.
  • For a histogram, y is one-dimensional and non-empty. x must be None. Draw every series with the same explicit bin edges from comparison["bins"].

comparison may contain "x_limits" and "y_limits". Each supplied limit is a pair of finite numbers in increasing order. Apply it exactly. Histograms require "bins": a one-dimensional finite array with at least two strictly increasing edges. Other plot forms must not receive "bins".

Use matplotlib.pyplot.subplots() and the explicit axes object. Set both axis labels, add a legend, and return a dictionary with exactly these keys:

figure, axes, audit

audit must be a new dictionary containing plot_form, series_order, x_label, y_label, x_limits, y_limits, and bins. Store applied limits as tuples, or None when absent. Store histogram bins as a tuple, or None for the other forms. Do not call show() or choose limits from one series independently of another.

Example

The axes contains two labelled lines in before, after order. Both use the same x- and y-limits, and the audit records those choices.

Your implementation

You may import NumPy as np and Matplotlib as plt. Do not print, show the figure, or ask for input.