def test_title(self): title = 'My Title' plot_history_figs, _ = plot_history(PlotHistoryTest.HISTORY, titles=title, close=False, show=False) plot_metrics_figs_no_title = [] for metric in PlotHistoryTest.METRICS: fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, ax=ax) plot_metrics_figs_no_title.append(fig) plot_metrics_figs_with_title = [] for metric in PlotHistoryTest.METRICS: fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, title=title, ax=ax) plot_metrics_figs_with_title.append(fig) for ( plot_history_fig, plot_metrics_fig_no_title, plot_metrics_fig_with_title, ) in zip(plot_history_figs, plot_metrics_figs_no_title, plot_metrics_figs_with_title): self.assertEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_with_title)) self.assertNotEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_no_title))
def test_labels(self): labels = ['Time', 'Loss', 'Accuracy'] plot_history_figs, _ = plot_history(PlotHistoryTest.HISTORY, labels=labels, close=False, show=False) plot_metrics_figs_no_labels = [] for metric in PlotHistoryTest.METRICS: fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, ax=ax) plot_metrics_figs_no_labels.append(fig) plot_metrics_figs_with_labels = [] for metric, label in zip(PlotHistoryTest.METRICS, labels): fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, label=label, ax=ax) plot_metrics_figs_with_labels.append(fig) for ( plot_history_fig, plot_metrics_fig_no_labels, plot_metrics_fig_with_labels, ) in zip(plot_history_figs, plot_metrics_figs_no_labels, plot_metrics_figs_with_labels): self.assertEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_with_labels)) self.assertNotEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_no_labels))
def test_different_titles(self): titles = ['Time', 'Loss', 'Accuracy'] plot_history_figs, _ = plot_history(PlotHistoryTest.HISTORY, titles=titles, close=False, show=False) plot_metrics_figs_no_title = [] for metric in PlotHistoryTest.METRICS: fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, ax=ax) plot_metrics_figs_no_title.append(fig) plot_metrics_figs_with_title = [] for metric, title in zip(PlotHistoryTest.METRICS, titles): fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, title=title, ax=ax) plot_metrics_figs_with_title.append(fig) for ( plot_history_fig, plot_metrics_fig_no_title, plot_metrics_fig_with_title, ) in zip(plot_history_figs, plot_metrics_figs_no_title, plot_metrics_figs_with_title): self.assertEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_with_title)) self.assertNotEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig_no_title))
def test_plot_metrics_use_gca(self): fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, 'loss', ax=ax) image_with_provided_ax = self._to_image(fig) plot_metric(PlotHistoryTest.HISTORY, 'loss') image_with_gca = self._to_image(plt.gcf()) self.assertEqual(image_with_provided_ax, image_with_gca)
def test_compare_plot_history_plot_metric(self): plot_history_figs, _ = plot_history(PlotHistoryTest.HISTORY, close=False, show=False) plot_metrics_figs = [] for metric in PlotHistoryTest.METRICS: fig, ax = plt.subplots() plot_metric(PlotHistoryTest.HISTORY, metric, ax=ax) plot_metrics_figs.append(fig) for plot_history_fig, plot_metrics_fig in zip(plot_history_figs, plot_metrics_figs): self.assertEqual(self._to_image(plot_history_fig), self._to_image(plot_metrics_fig))