コード例 #1
0
 def test_set_figure_size(self):
     """Test setting a valid figure size."""
     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)))
コード例 #2
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)
コード例 #3
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))
コード例 #4
0
 def test_set_axes_options_ylim(self):
     """_set_axes_options() should set the y-axis limits."""
     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))
コード例 #5
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')
コード例 #6
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")
コード例 #7
0
 def test_set_figure_size_long_labels(self):
     """Test setting a figure size that has really long labels."""
     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))
コード例 #8
0
 def test_set_figure_size(self):
     """Test setting a valid figure size."""
     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)))
コード例 #9
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))
コード例 #10
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)
コード例 #11
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")
コード例 #12
0
 def test_set_axes_options_ylim(self):
     """_set_axes_options() should set the y-axis limits."""
     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))
コード例 #13
0
 def test_set_figure_size_long_labels(self):
     """Test setting a figure size that has really long labels."""
     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))
コード例 #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')