Plots iteration runtimes. Parameters ---------- result Result for which to plot runtimes. ax Axes object to draw the plot on. One will be created if not provided.
(result: Result, ax: plt.Axes | None = None)
| 5 | |
| 6 | |
| 7 | def plot_runtimes(result: Result, ax: plt.Axes | None = None): |
| 8 | """ |
| 9 | Plots iteration runtimes. |
| 10 | |
| 11 | Parameters |
| 12 | ---------- |
| 13 | result |
| 14 | Result for which to plot runtimes. |
| 15 | ax |
| 16 | Axes object to draw the plot on. One will be created if not provided. |
| 17 | """ |
| 18 | if not ax: |
| 19 | _, ax = plt.subplots() |
| 20 | |
| 21 | x = 1 + np.arange(result.num_iterations) |
| 22 | ax.plot(x, result.stats.runtimes) |
| 23 | |
| 24 | if result.num_iterations > 1: # need data to plot a trendline |
| 25 | b, c = np.polyfit(x, result.stats.runtimes, 1) |
| 26 | ax.plot(b * x + c) |
| 27 | |
| 28 | ax.set_xlim(left=0) |
| 29 | |
| 30 | ax.set_xlabel("Iteration (#)") |
| 31 | ax.set_ylabel("Runtime (s)") |
| 32 | ax.set_title("Iteration runtimes") |