Ejemplo n.º 1
0
 def test_set_figure_size(self):
     fig, ax = plt.subplots()
     _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.assertTrue(np.array_equal(fig.get_size_inches(), (3, 4)))
Ejemplo n.º 2
0
 def test_set_axes_options(self):
     fig, ax = plt.subplots()
     _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")
Ejemplo n.º 3
0
 def test_set_figure_size(self):
     fig, ax = plt.subplots()
     _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.assertTrue(np.array_equal(fig.get_size_inches(), (3, 4)))
 def test_set_axes_options_bad_ylim(self):
     """_set_axes_options() should raise an exception when given non-numeric
     y limits."""
     fig, ax = plt.subplots()
     with npt.assert_raises(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)
Ejemplo n.º 5
0
 def test_set_axes_options(self):
     fig, ax = plt.subplots()
     _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")
Ejemplo n.º 6
0
 def test_set_axes_options_ylim(self):
     fig, ax = plt.subplots()
     _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.assertEqual(ax.get_ylim(), (0.0, 1.0))
Ejemplo n.º 7
0
    def test_set_axes_options_x_values_as_tick_labels(self):
        fig, ax = plt.subplots()
        _set_axes_options(ax, "Plot Title", "x-axis label", "y-axis label", x_values=[42, 45, 800])

        self.assertEqual(ax.get_title(), "Plot Title")
        self.assertEqual(ax.get_ylabel(), "y-axis label")
        self.assertEqual(ax.get_xticklabels()[0].get_text(), "42")
        self.assertEqual(ax.get_xticklabels()[1].get_text(), "45")
        self.assertEqual(ax.get_xticklabels()[2].get_text(), "800")
Ejemplo n.º 8
0
 def test_set_axes_options_invalid_x_tick_labels_orientation(self):
     fig, ax = plt.subplots()
     with npt.assert_raises(ValueError):
         _set_axes_options(ax,
                           "Plot Title",
                           "x-axis label",
                           "y-axis label",
                           x_tick_labels=["T0", "T1"],
                           x_tick_labels_orientation='brofist')
 def test_set_figure_size_invalid(self):
     """Test setting a figure size using invalid dimensions."""
     fig, ax = plt.subplots()
     _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.assertTrue(np.array_equal(fig.get_size_inches(), orig_fig_size))
Ejemplo n.º 10
0
    def test_set_axes_options_x_values_as_tick_labels(self):
        fig, ax = plt.subplots()
        _set_axes_options(ax, "Plot Title", "x-axis label", "y-axis label",
                          x_values=[42, 45, 800])

        self.assertEqual(ax.get_title(), "Plot Title")
        self.assertEqual(ax.get_ylabel(), "y-axis label")
        self.assertEqual(ax.get_xticklabels()[0].get_text(), '42')
        self.assertEqual(ax.get_xticklabels()[1].get_text(), '45')
        self.assertEqual(ax.get_xticklabels()[2].get_text(), '800')
Ejemplo n.º 11
0
 def test_set_figure_size_long_labels(self):
     fig, ax = plt.subplots()
     _set_axes_options(ax, 'foo', 'x_foo', 'y_foo',
                       x_tick_labels=['foofoofooooooooooooooooooooooooo'
                                      'oooooooooooooooooooooooooooooooo'
                                      'oooooooooooooooooooooooooooooooo'
                                      'oooo', 'barbarbar'],
                       x_tick_labels_orientation='vertical')
     npt.assert_warns(RuntimeWarning, _set_figure_size, fig, 3, 3)
     npt.assert_array_equal(fig.get_size_inches(), (3, 3))
Ejemplo n.º 12
0
 def test_set_axes_options_bad_ylim(self):
     fig, ax = plt.subplots()
     with npt.assert_raises(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_axes_options(self):
     """_set_axes_options() should set the labels on the axes and not raise
     any exceptions."""
     fig, ax = plt.subplots()
     _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")
Ejemplo n.º 14
0
 def test_set_axes_options_invalid_x_tick_labels_orientation(self):
     fig, ax = plt.subplots()
     with npt.assert_raises(ValueError):
         _set_axes_options(
             ax,
             "Plot Title",
             "x-axis label",
             "y-axis label",
             x_tick_labels=["T0", "T1"],
             x_tick_labels_orientation="brofist",
         )
Ejemplo n.º 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 = plt.subplots()
     with npt.assert_raises(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)
Ejemplo n.º 16
0
 def test_set_figure_size_invalid(self):
     """Test setting a figure size using invalid dimensions."""
     fig, ax = plt.subplots()
     _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.assertTrue(np.array_equal(fig.get_size_inches(), orig_fig_size))
Ejemplo n.º 17
0
 def test_set_axes_options_bad_ylim(self):
     fig, ax = plt.subplots()
     with npt.assert_raises(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,
         )
Ejemplo n.º 18
0
 def test_set_axes_options(self):
     """_set_axes_options() should set the labels on the axes and not raise
     any exceptions."""
     fig, ax = plt.subplots()
     _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")
Ejemplo n.º 19
0
 def test_set_figure_size_long_labels(self):
     fig, ax = plt.subplots()
     _set_axes_options(ax,
                       'foo',
                       'x_foo',
                       'y_foo',
                       x_tick_labels=[
                           'foofoofooooooooooooooooooooooooo'
                           'oooooooooooooooooooooooooooooooo'
                           'oooooooooooooooooooooooooooooooo'
                           'oooo', 'barbarbar'
                       ],
                       x_tick_labels_orientation='vertical')
     npt.assert_warns(RuntimeWarning, _set_figure_size, fig, 3, 3)
     npt.assert_array_equal(fig.get_size_inches(), (3, 3))
Ejemplo n.º 20
0
    def test_set_figure_size_long_labels(self):
        fig, ax = plt.subplots()
        _set_axes_options(ax, 'foo', 'x_foo', 'y_foo',
                          x_tick_labels=['foofoofooooooooooooooooooooooooo'
                                         'oooooooooooooooooooooooooooooooo'
                                         'oooooooooooooooooooooooooooooooo'
                                         'oooo', 'barbarbar'],
                          x_tick_labels_orientation='vertical')

        # adapted from SO example here: http://stackoverflow.com/a/3892301
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            _set_figure_size(fig, 3, 3)
            self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
        npt.assert_array_equal(fig.get_size_inches(), (3, 3))
Ejemplo n.º 21
0
 def test_set_figure_size_long_labels(self):
     fig, ax = plt.subplots()
     _set_axes_options(
         ax,
         "foo",
         "x_foo",
         "y_foo",
         x_tick_labels=[
             "foofoofooooooooooooooooooooooooo"
             "oooooooooooooooooooooooooooooooo"
             "oooooooooooooooooooooooooooooooo"
             "oooo",
             "barbarbar",
         ],
         x_tick_labels_orientation="vertical",
     )
     npt.assert_warns(RuntimeWarning, _set_figure_size, fig, 3, 3)
     npt.assert_array_equal(fig.get_size_inches(), (3, 3))