Example #1
0
 def test_boxplot_relative_error_plot_raise_column_not_found(self):
     msg = 'num_sets or relative_error not found in df.'
     with self.assertRaisesRegex(ValueError, msg):
         _ = plotting.boxplot_relative_error(
             get_relative_error_by_num_sets(), 'num_set', 'relative_error')
     with self.assertRaisesRegex(ValueError, msg):
         _ = plotting.boxplot_relative_error(
             get_relative_error_by_num_sets(), 'num_set', 'rel_err')
 def test_boxplot_relative_error_plot_xticks(self):
   df = get_relative_error_by_num_sets()
   ax = plotting.boxplot_relative_error(
       df, 'num_sets', 'relative_error')
   xlabels = [x.get_text() for x in ax.get_xticklabels()]
   expected = [str(x) for x in sorted(df['num_sets'].unique())]
   self.assertListEqual(xlabels, expected)
 def f(x):
     # Make a plot.
     ax = plotting.boxplot_relative_error(
         x[RAW_RESULT_DF],
         num_sets=simulator.NUM_SETS,
         relative_error=simulator.RELATIVE_ERROR)
     ax.set_title(f'{x[SCENARIO_NAME]}\n{x[ESTIMATOR_NAME]}')
     ax.set_ylim(-0.1, 0.1)
     for tick in ax.get_xticklabels():
         tick.set_rotation(90)
     # Save the plot to file.
     fig = ax.get_figure()
     plot_file = os.path.join(
         self.analysis_file_dirs[x[ESTIMATOR_NAME]][x[SCENARIO_NAME]],
         BOXPLOT_FILENAME)
     fig.set_size_inches(w=self.plot_params[BOXPLOT_SIZE_WIDTH_INCH],
                         h=self.plot_params[BOXPLOT_SIZE_HEIGHT_INCH])
     fig.savefig(plot_file)
Example #4
0
 def plot_one_estimator_under_one_scenario(df):
     ax = plotting.boxplot_relative_error(
         df,
         num_sets=simulator.NUM_SETS,
         relative_error=self.error_metric_column,
         metric_name=self.error_metric_name)
     scenario_name = df[SCENARIO_NAME].values[0]
     estimator_name = df[SKETCH_ESTIMATOR_NAME].values[0]
     ax.set_title(f'{scenario_name}\n{estimator_name}')
     ax.set_ylim(-0.1, 0.1)
     for tick in ax.get_xticklabels():
         tick.set_rotation(self.plot_params[XLABEL_ROTATE])
     # Save the plot to file.
     fig = ax.get_figure()
     plot_file = os.path.join(
         self.analysis_file_dirs[estimator_name][scenario_name],
         BOXPLOT_FILENAME)
     fig.set_size_inches(w=self.plot_params[BOXPLOT_SIZE_WIDTH_INCH],
                         h=self.plot_params[BOXPLOT_SIZE_HEIGHT_INCH])
     fig.savefig(plot_file)
     plt.close(fig)
 def test_boxplot_relative_error_plot_returns(self):
   ax = plotting.boxplot_relative_error(
       get_relative_error_by_num_sets(),
       'num_sets', 'relative_error')
   self.assertIsInstance(ax, matplotlib.axes.Axes)