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_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_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_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