예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    def test_color_box_plot_invalid_input(self):
        """Should throw an exception on invalid input."""
        # Invalid color.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        self.assertRaises(ValueError, _color_box_plot, ax, box_plot,
                          ['red', 'foobarbaz', 'blue'])

        # Wrong number of colors.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        self.assertRaises(ValueError, _color_box_plot, ax, box_plot,
                          ['blue', (1, 1, 0.9)])
예제 #6
0
    def test_color_box_plot_invalid_input(self):
        """Should throw an exception on invalid input."""
        # Invalid color.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        self.assertRaises(ValueError, _color_box_plot, ax, box_plot,
                          ['red', 'foobarbaz', 'blue'])

        # Wrong number of colors.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        self.assertRaises(ValueError, _color_box_plot, ax, box_plot,
                          ['blue', (1, 1, 0.9)])
예제 #7
0
    def test_color_box_plot(self):
        """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', 'w', (1, 1, 0.9)])

        # Some colors are None.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, ['blue', None, (1, 1, 0.9)])

        # All colors are None.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, [None, None, None])
예제 #8
0
    def test_color_box_plot(self):
        """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', 'w', (1, 1, 0.9)])

        # Some colors are None.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, ['blue', None, (1, 1, 0.9)])

        # All colors are None.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, [None, None, None])
예제 #9
0
 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')
예제 #10
0
 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')
예제 #11
0
    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
예제 #12
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)
예제 #13
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)
예제 #14
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))
예제 #15
0
 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)
예제 #16
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)
예제 #17
0
 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")
예제 #18
0
 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])
예제 #19
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))
예제 #20
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(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)
예제 #21
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')
     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)
예제 #22
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(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)
예제 #23
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)
예제 #24
0
    def test_color_box_plot(self):
        """Should not throw an exception when passed the proper input."""
        # Single color.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, 'blue')

        # Multiple colors.
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, ['blue', 'w', (1, 1, 0.9)])

        # Multiple colors (some are None).
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, ['blue', None, (1, 1, 0.9)])

        # Multiple colors (all are None).
        fig, ax = _create_plot()
        box_plot = boxplot(self.ValidTypicalBoxData)
        _color_box_plot(ax, box_plot, [None, None, None])
예제 #25
0
 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")
예제 #26
0
 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)
예제 #27
0
 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])
예제 #28
0
    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
예제 #29
0
 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")
예제 #30
0
 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')
예제 #31
0
 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)
예제 #32
0
 def test_plot_box_data_empty(self):
     """Should ignore empty distribution."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     self.assertTrue(result is None)
예제 #33
0
 def test_plot_box_data_empty(self):
     """Should ignore empty distribution."""
     fig, ax = _create_plot()
     result = _plot_box_data(ax, [], 'blue', 0.33, 55, 1.5, 'stdv')
     self.assertTrue(result is None)
예제 #34
0
 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)
예제 #35
0
 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")
예제 #36
0
 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')