def test_figure_size_is_kwarg_size(self): size = (6, 6) with patch('matplotlib.figure.Figure.set_size_inches') as mock_set, \ patch('latexipy._latexipy.save_figure'): with lp.figure('filename', size=size): pass mock_set.assert_called_once_with(*size)
def test_default_size_is_figure_size(self): default_size = lp.figure_size() with patch('matplotlib.figure.Figure.set_size_inches') as mock_set, \ patch('latexipy._latexipy.save_figure'): with lp.figure('filename'): pass mock_set.assert_called_once_with(*default_size)
def test_parameters_passed_all_kwargs_default(self): params = inspect.signature(lp.figure).parameters with patch('matplotlib.figure.Figure.set_size_inches'), \ patch('latexipy._latexipy.save_figure') as mock_save_figure: with lp.figure('filename'): pass mock_save_figure.assert_called_once_with( filename='filename', directory=params['directory'].default, exts=params['exts'].default, mkdir=params['mkdir'].default, from_context_manager=True, )
plot_sin_and_cos() # You can change the size. 0.45\textwidth is useful when using two columns. with figure('sincos_small', size=lp.figure_size(0.45)): plot_sin_and_cos() # A ratio of 1 is great for squares. with figure('sincos_square', size=lp.figure_size(ratio=1)): plot_sin_and_cos() # And we can have a high figure if, for instance, stacking subplots. with figure('sincos_tall', size=lp.figure_size(0.6, ratio=2)): plot_sin_and_cos() # It is equivalent to the original function with the right arguments. with lp.figure('sincos_defaults_no_partial', directory=DIRECTORY): plot_sin_and_cos() # You can temporarily change parameters. To increase font size: font_size = 10 with lp.temp_params(font_size=font_size): with figure('sincos_big_font_temp'): plot_sin_and_cos() # You can permanently change them too. font_size = 10 params = lp.PARAMS.copy() params.update({param: font_size for param in params if 'size' in param}) lp.latexify(params) with figure('sincos_big_font_permanent'):