def test_plot_bar_data_empty(self):
        """_plot_bar_data() should not error when given empty list of data,
        but should not plot anything."""
        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [], 'red', 0.5, 3.75, 1.5, 'stdv')
        self.assertTrue(result is None)

        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [], 'red', 0.5, 3.75, 1.5, 'sem')
        self.assertTrue(result is None)
    def test_create_legend(self):
        """_create_box_plot_legend() should create a legend on valid input."""
        fig, ax = _create_plot()
        _create_legend(ax, ['b', 'r'], ['dist1', 'dist2'], 'colors')
        self.assertEqual(len(ax.get_legend().get_texts()), 2)

        fig, ax = _create_plot()
        _create_legend(ax, ['^', '<', '>'], ['dist1', 'dist2', 'dist3'],
                'symbols')
        self.assertEqual(len(ax.get_legend().get_texts()), 3)
    def test_create_legend(self):
        """_create_box_plot_legend() should create a legend on valid input."""
        fig, ax = _create_plot()
        _create_legend(ax, ['b', 'r'], ['dist1', 'dist2'], 'colors')
        self.assertEqual(len(ax.get_legend().get_texts()), 2)

        fig, ax = _create_plot()
        _create_legend(ax, ['^', '<', '>'], ['dist1', 'dist2', 'dist3'],
                       'symbols')
        self.assertEqual(len(ax.get_legend().get_texts()), 3)
    def test_plot_bar_data_empty(self):
        """_plot_bar_data() should not error when given empty list of data,
        but should not plot anything."""
        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [], 'red', 0.5, 3.75, 1.5, 'stdv')
        self.assertTrue(result is None)

        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [], 'red', 0.5, 3.75, 1.5, 'sem')
        self.assertTrue(result is None)
 def test_create_legend_invalid_input(self):
     """Test raises error on bad input."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _create_legend, ax,
             ['^', '<', '>'], ['dist1', 'dist2'], 'symbols')
     self.assertRaises(ValueError, _create_legend, ax, ['^', '<', '>'],
             ['dist1', 'dist2', 'dist3'], 'foo')
 def test_create_legend_invalid_input(self):
     """Test raises error on bad input."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _create_legend, ax, ['^', '<', '>'],
                       ['dist1', 'dist2'], 'symbols')
     self.assertRaises(ValueError, _create_legend, ax, ['^', '<', '>'],
                       ['dist1', 'dist2', 'dist3'], 'foo')
    def test_set_figure_size_long_labels(self):
        """Test setting a figure size that has really long labels."""
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out

            fig, ax = _create_plot()
            _set_axes_options(
                ax,
                'foo',
                'x_foo',
                'y_foo',
                x_tick_labels=[
                    'foofoofooooooooooooooooooooooooo'
                    'ooooooooooooooooooooooooooooooooooooooooooooooo'
                    'ooooooooooooooooooooo', 'barbarbar'
                ],
                x_tick_labels_orientation='vertical')
            _set_figure_size(fig, 3, 3)
            self.assertFloatEqual(fig.get_size_inches(), (3, 3))
            output = out.getvalue().strip()
            self.assertEqual(
                output,
                "Warning: could not automatically resize plot to make room for "
                "axes labels and plot title. This can happen if the labels or "
                "title are extremely long and the plot size is too small. Your "
                "plot may have its labels and/or title cut-off. To fix this, "
                "try increasing the plot's size (in inches) and try again.")
        finally:
            sys.stdout = saved_stdout
 def test_set_axes_options_bad_ylim(self):
     """_set_axes_options() should raise an exception when given non-numeric
     y limits."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _set_axes_options, ax, "Plot Title",
                       "x-axis label", "y-axis label",
                       x_tick_labels=["T0", "T1", "T2"], y_min='car',
                       y_max=30)
 def test_set_figure_size(self):
     """Test setting a valid figure size."""
     fig, ax = _create_plot()
     _set_axes_options(ax, 'foo', 'x_foo', 'y_foo',
                       x_tick_labels=['foofoofoo', 'barbarbar'],
                       x_tick_labels_orientation='vertical')
     _set_figure_size(fig, 3, 4)
     self.assertFloatEqual(fig.get_size_inches(), (3, 4))
    def test_plot_bar_data(self):
        """_plot_bar_data() should return a list of Rectangle objects."""
        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [1, 2, 3], 'red', 0.5, 3.75, 1.5, 'stdv')
        self.assertEqual(result[0].__class__.__name__, "Rectangle")
        self.assertEqual(len(result), 1)
        self.assertFloatEqual(result[0].get_width(), 0.5)
        self.assertFloatEqual(result[0].get_facecolor(), (1.0, 0.0, 0.0, 1.0))
        self.assertFloatEqual(result[0].get_height(), 2.0)

        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [1, 2, 3], 'red', 0.5, 3.75, 1.5, 'sem')
        self.assertEqual(result[0].__class__.__name__, "Rectangle")
        self.assertEqual(len(result), 1)
        self.assertFloatEqual(result[0].get_width(), 0.5)
        self.assertFloatEqual(result[0].get_facecolor(), (1.0, 0.0, 0.0, 1.0))
        self.assertFloatEqual(result[0].get_height(), 2.0)
    def test_plot_bar_data(self):
        """_plot_bar_data() should return a list of Rectangle objects."""
        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [1, 2, 3], 'red', 0.5, 3.75, 1.5, 'stdv')
        self.assertEqual(result[0].__class__.__name__, "Rectangle")
        self.assertEqual(len(result), 1)
        self.assertFloatEqual(result[0].get_width(), 0.5)
        self.assertFloatEqual(result[0].get_facecolor(), (1.0, 0.0, 0.0, 1.0))
        self.assertFloatEqual(result[0].get_height(), 2.0)

        fig, ax = _create_plot()
        result = _plot_bar_data(ax, [1, 2, 3], 'red', 0.5, 3.75, 1.5, 'sem')
        self.assertEqual(result[0].__class__.__name__, "Rectangle")
        self.assertEqual(len(result), 1)
        self.assertFloatEqual(result[0].get_width(), 0.5)
        self.assertFloatEqual(result[0].get_facecolor(), (1.0, 0.0, 0.0, 1.0))
        self.assertFloatEqual(result[0].get_height(), 2.0)
 def test_set_figure_size_invalid(self):
     """Test setting a figure size using invalid dimensions."""
     fig, ax = _create_plot()
     _set_axes_options(ax, 'foo', 'x_foo', 'y_foo',
                       x_tick_labels=['foofoofoo', 'barbarbar'],
                       x_tick_labels_orientation='vertical')
     orig_fig_size = fig.get_size_inches()
     _set_figure_size(fig, -1, 0)
     self.assertFloatEqual(fig.get_size_inches(), orig_fig_size)
 def test_set_axes_options_ylim(self):
     """_set_axes_options() should set the y-axis limits."""
     fig, ax = _create_plot()
     _set_axes_options(ax, "Plot Title", "x-axis label", "y-axis label",
                       x_tick_labels=["T0", "T1", "T2"], y_min=0, y_max=1)
     self.assertEqual(ax.get_title(), "Plot Title")
     self.assertEqual(ax.get_ylabel(), "y-axis label")
     self.assertEqual(ax.get_xticklabels()[0].get_text(), "T0")
     self.assertEqual(ax.get_xticklabels()[1].get_text(), "T1")
     self.assertFloatEqual(ax.get_ylim(), [0, 1])
 def test_set_axes_options(self):
     """_set_axes_options() should set the labels on the axes and not raise
     any exceptions."""
     fig, ax = _create_plot()
     _set_axes_options(ax, "Plot Title", "x-axis label", "y-axis label",
                       x_tick_labels=["T0", "T1"])
     self.assertEqual(ax.get_title(), "Plot Title")
     self.assertEqual(ax.get_ylabel(), "y-axis label")
     self.assertEqual(ax.get_xticklabels()[0].get_text(), "T0")
     self.assertEqual(ax.get_xticklabels()[1].get_text(), "T1")
 def test_create_box_plot_legend_invalid_input(self):
     """_create_box_plot_legend() should raise an exception when the lengths
     of the input lists don't match up."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _create_box_plot_legend, [[], []], ax,
             ['b', 'm', 'r'], 2, ['dist1', 'dist2'])
     self.assertRaises(ValueError, _create_box_plot_legend, [[], []], ax,
             ['b', 'm', 'r'], 3, ['dist1', 'dist2', 'dist3'])
     self.assertRaises(ValueError, _create_box_plot_legend, [[], [], []],
             ax, ['b', 'm', 'r'], 3, ['dist1', 'dist2'])
示例#16
0
 def test_plot_box_data(self):
     """_plot_box_data() should return a dictionary for Line2D's."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [0, 0, 7, 8, -3, 44], 'blue', 0.33, 55,
             1.5, 'stdv')
     self.assertEqual(type(result), dict)
     # make sure the values are not empty
     for key in ['boxes', 'medians', 'whiskers', 'fliers', 'caps']:
         val = result[key]
         self.assertTrue(len(val), 0)
示例#17
0
 def test_plot_box_data_empty(self):
     """_plot_box_data() should not error when given empty list of data,
     but should not plot anything."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     # the original test was poor as it was testing a property of matplotlib
     # I'm simply exercising this here. These capabilities will be dropped
     # in a future version.
     for key in ['boxes', 'medians', 'whiskers', 'fliers', 'caps']:
         val = result[key]
示例#18
0
 def test_plot_box_data(self):
     """_plot_box_data() should return a dictionary for Line2D's."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [0, 0, 7, 8, -3, 44], 'blue', 0.33, 55,
                             1.5, 'stdv')
     self.assertEqual(type(result), dict)
     # make sure the values are not empty
     for key in ['boxes', 'medians', 'whiskers', 'fliers', 'caps']:
         val = result[key]
         self.assertTrue(len(val), 0)
示例#19
0
 def test_plot_box_data_empty(self):
     """_plot_box_data() should not error when given empty list of data,
     but should not plot anything."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     # the original test was poor as it was testing a property of matplotlib
     # I'm simply exercising this here. These capabilities will be dropped
     # in a future version.
     for key in ['boxes', 'medians', 'whiskers', 'fliers', 'caps']:
         val = result[key]
 def test_plot_box_data(self):
     """_plot_box_data() should return a dictionary for Line2D's."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [0, 0, 7, 8, -3, 44], 'blue', 0.33, 55,
             1.5, 'stdv')
     self.assertEqual(result.__class__.__name__, "dict")
     self.assertEqual(len(result['boxes']), 1)
     self.assertEqual(len(result['medians']), 1)
     self.assertEqual(len(result['whiskers']), 2)
     self.assertEqual(len(result['fliers']), 2)
     self.assertEqual(len(result['caps']), 2)
 def test_plot_box_data(self):
     """_plot_box_data() should return a dictionary for Line2D's."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [0, 0, 7, 8, -3, 44], 'blue', 0.33, 55,
                             1.5, 'stdv')
     self.assertEqual(result.__class__.__name__, "dict")
     self.assertEqual(len(result['boxes']), 1)
     self.assertEqual(len(result['medians']), 1)
     self.assertEqual(len(result['whiskers']), 2)
     self.assertEqual(len(result['fliers']), 2)
     self.assertEqual(len(result['caps']), 2)
 def test_plot_box_data_empty(self):
     """_plot_box_data() should not error when given empty list of data,
     but should not plot anything."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     self.assertEqual(result.__class__.__name__, "dict")
     self.assertEqual(len(result['boxes']), 0)
     self.assertEqual(len(result['medians']), 0)
     self.assertEqual(len(result['whiskers']), 0)
     self.assertEqual(len(result['fliers']), 0)
     self.assertEqual(len(result['caps']), 0)
 def test_set_figure_size(self):
     """Test setting a valid figure size."""
     fig, ax = _create_plot()
     _set_axes_options(ax,
                       'foo',
                       'x_foo',
                       'y_foo',
                       x_tick_labels=['foofoofoo', 'barbarbar'],
                       x_tick_labels_orientation='vertical')
     _set_figure_size(fig, 3, 4)
     self.assertFloatEqual(fig.get_size_inches(), (3, 4))
 def test_plot_box_data_empty(self):
     """_plot_box_data() should not error when given empty list of data,
     but should not plot anything."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     self.assertEqual(result.__class__.__name__, "dict")
     self.assertEqual(len(result['boxes']), 0)
     self.assertEqual(len(result['medians']), 0)
     self.assertEqual(len(result['whiskers']), 0)
     self.assertEqual(len(result['fliers']), 0)
     self.assertEqual(len(result['caps']), 0)
 def test_set_figure_size_invalid(self):
     """Test setting a figure size using invalid dimensions."""
     fig, ax = _create_plot()
     _set_axes_options(ax,
                       'foo',
                       'x_foo',
                       'y_foo',
                       x_tick_labels=['foofoofoo', 'barbarbar'],
                       x_tick_labels_orientation='vertical')
     orig_fig_size = fig.get_size_inches()
     _set_figure_size(fig, -1, 0)
     self.assertFloatEqual(fig.get_size_inches(), orig_fig_size)
 def test_set_axes_options_bad_ylim(self):
     """_set_axes_options() should raise an exception when given non-numeric
     y limits."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError,
                       _set_axes_options,
                       ax,
                       "Plot Title",
                       "x-axis label",
                       "y-axis label",
                       x_tick_labels=["T0", "T1", "T2"],
                       y_min='car',
                       y_max=30)
 def test_create_standard_legend_invalid_input(self):
     """_create_standard_legend() should raise an exception when given a
     list of distribution examples that contains one or more null values, or
     if the lengths of the input lists don't match up."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _create_standard_legend, [None, []], ax,
             ['^', '<'], 2, ['dist1', 'dist2'])
     self.assertRaises(ValueError, _create_standard_legend, [[], []], ax,
             ['^', '<', '>'], 2, ['dist1', 'dist2'])
     self.assertRaises(ValueError, _create_standard_legend, [[], []], ax,
             ['^', '<', '>'], 3, ['dist1', 'dist2', 'dist3'])
     self.assertRaises(ValueError, _create_standard_legend, [[], [], []],
             ax, ['^', '<', '>'], 3, ['dist1', 'dist2'])
 def test_set_axes_options(self):
     """_set_axes_options() should set the labels on the axes and not raise
     any exceptions."""
     fig, ax = _create_plot()
     _set_axes_options(ax,
                       "Plot Title",
                       "x-axis label",
                       "y-axis label",
                       x_tick_labels=["T0", "T1"])
     self.assertEqual(ax.get_title(), "Plot Title")
     self.assertEqual(ax.get_ylabel(), "y-axis label")
     self.assertEqual(ax.get_xticklabels()[0].get_text(), "T0")
     self.assertEqual(ax.get_xticklabels()[1].get_text(), "T1")
 def test_set_axes_options_ylim(self):
     """_set_axes_options() should set the y-axis limits."""
     fig, ax = _create_plot()
     _set_axes_options(ax,
                       "Plot Title",
                       "x-axis label",
                       "y-axis label",
                       x_tick_labels=["T0", "T1", "T2"],
                       y_min=0,
                       y_max=1)
     self.assertEqual(ax.get_title(), "Plot Title")
     self.assertEqual(ax.get_ylabel(), "y-axis label")
     self.assertEqual(ax.get_xticklabels()[0].get_text(), "T0")
     self.assertEqual(ax.get_xticklabels()[1].get_text(), "T1")
     self.assertFloatEqual(ax.get_ylim(), [0, 1])
    def test_set_figure_size_long_labels(self):
        """Test setting a figure size that has really long labels."""
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out

            fig, ax = _create_plot()
            _set_axes_options(ax, 'foo', 'x_foo', 'y_foo',
                              x_tick_labels=['foofoofooooooooooooooooooooooooo'
                              'ooooooooooooooooooooooooooooooooooooooooooooooo'
                              'ooooooooooooooooooooo', 'barbarbar'],
                              x_tick_labels_orientation='vertical')
            _set_figure_size(fig, 3, 3)
            self.assertFloatEqual(fig.get_size_inches(), (3, 3))
            output = out.getvalue().strip()
            self.assertEqual(output,
            "Warning: could not automatically resize plot to make room for "
            "axes labels and plot title. This can happen if the labels or "
            "title are extremely long and the plot size is too small. Your "
            "plot may have its labels and/or title cut-off. To fix this, "
            "try increasing the plot's size (in inches) and try again.")
        finally:
            sys.stdout = saved_stdout
 def test_plot_bar_data_bad_error_bar_type(self):
     """_plot_bar_data() should raise an exception on bad error bar type."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _plot_bar_data, ax, [1, 2, 3], 'red',
             0.5, 3.75, 1.5, 'var')
 def test_color_box_plot(self):
     """_color_box_plot() should not throw an exception when passed the
     proper input."""
     fig, ax = _create_plot()
     box_plot = boxplot(self.ValidTypicalBoxData)
     _color_box_plot(ax, box_plot, 'blue')
 def test_color_box_plot(self):
     """_color_box_plot() should not throw an exception when passed the
     proper input."""
     fig, ax = _create_plot()
     box_plot = boxplot(self.ValidTypicalBoxData)
     _color_box_plot(ax, box_plot, 'blue')
 def test_plot_bar_data_bad_error_bar_type(self):
     """_plot_bar_data() should raise an exception on bad error bar type."""
     fig, ax = _create_plot()
     self.assertRaises(ValueError, _plot_bar_data, ax, [1, 2, 3], 'red',
                       0.5, 3.75, 1.5, 'var')
 def test_create_plot(self):
     """_create_plot() should return a tuple containing a Figure and
     Axes."""
     fig, ax = _create_plot()
     self.assertEqual(fig.__class__.__name__, "Figure")
     self.assertEqual(ax.__class__.__name__, "AxesSubplot")
 def test_create_box_plot_legend_valid_input(self):
     """_create_box_plot_legend() should create a legend on valid input."""
     fig, ax = _create_plot()
     _create_box_plot_legend([[], []], ax, ['b', 'r'], 2,
             ['dist1', 'dist2'])
 def test_plot_scatter_data(self):
     """_plot_scatter_data() should return a Collection instance."""
     fig, ax = _create_plot()
     result = _plot_scatter_data(ax, [1, 2, 3], '^', 0.77, 1, 1.5, 'stdv')
     self.assertFloatEqual(result.get_sizes(), 20)
 def test_plot_scatter_data(self):
     """_plot_scatter_data() should return a Collection instance."""
     fig, ax = _create_plot()
     result = _plot_scatter_data(ax, [1, 2, 3], '^', 0.77, 1, 1.5, 'stdv')
     self.assertFloatEqual(result.get_sizes(), 20)
 def test_create_plot(self):
     """_create_plot() should return a tuple containing a Figure and
     Axes."""
     fig, ax = _create_plot()
     self.assertEqual(fig.__class__.__name__, "Figure")
     self.assertEqual(ax.__class__.__name__, "AxesSubplot")