Exemplo n.º 1
0
 def test_defaults(self):
     with patch('matplotlib.rcParams.update') as mock_update, \
             patch('matplotlib.pyplot.switch_backend') as mock_switch:
         old_params = dict(plt.rcParams)
         with lp.temp_params():
             mock_update.assert_called_with(old_params)
         mock_update.assert_called_with(old_params)
Exemplo n.º 2
0
 def test_params_dict(self):
     with patch('matplotlib.rcParams.update') as mock_update, \
             patch('matplotlib.pyplot.switch_backend') as mock_switch:
         old_params = dict(plt.rcParams)
         with lp.temp_params(params_dict={'font.family': 'sans-serif'}):
             called_with = mock_update.call_args[0][0]
             assert called_with['font.family'] == 'sans-serif'
         mock_update.assert_called_with(old_params)
Exemplo n.º 3
0
 def test_font_size(self):
     with patch('matplotlib.rcParams.update') as mock_update, \
             patch('matplotlib.pyplot.switch_backend') as mock_switch:
         old_params = dict(plt.rcParams)
         with lp.temp_params(font_size=10):
             called_with = mock_update.call_args[0][0]
             print(called_with)
             assert all(called_with[k] == 10 for k in lp.PARAMS
                        if 'size' in k)
         mock_update.assert_called_with(old_params)
Exemplo n.º 4
0
    def test_params_dict_after_font_size(self):
        with patch('matplotlib.rcParams.update') as mock_update, \
                patch('matplotlib.pyplot.switch_backend') as mock_switch:
            old_params = dict(plt.rcParams)
            with lp.temp_params(font_size=10,
                                params_dict={
                                    'axes.labelsize': 12,
                                    'legend.fontsize': 12,
                                }):
                called_with = mock_update.call_args[0][0]
                assert called_with['font.size'] == 10
                assert called_with['axes.labelsize'] == 12
                assert called_with['axes.titlesize'] == 10
                assert called_with['legend.fontsize'] == 12
                assert called_with['xtick.labelsize'] == 10
                assert called_with['ytick.labelsize'] == 10

            mock_update.assert_called_with(old_params)
Exemplo n.º 5
0
    # 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'):
        plot_sin_and_cos()

    # Or revert at any time.
    lp.revert()
    with figure('sincos_after_revert'):