From f269631111d55574db694e01275d0f08e1661ac1 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Mon, 7 Aug 2023 11:40:56 +0200 Subject: [PATCH] add tests --- src/plopp/plotting/plot.py | 2 +- tests/plotting/plot_test.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/plopp/plotting/plot.py b/src/plopp/plotting/plot.py index 32b018c9..db75d2a3 100644 --- a/src/plopp/plotting/plot.py +++ b/src/plopp/plotting/plot.py @@ -106,7 +106,6 @@ def plot( 'vmax': vmax, 'autoscale': autoscale, 'figsize': figsize, - 'legend': legend, **kwargs, } @@ -128,6 +127,7 @@ def plot( *[Node(da) for da in data_arrays], errorbars=errorbars, mask_color=mask_color, + legend=legend, **common_args, ) elif ndim == 2: diff --git a/tests/plotting/plot_test.py b/tests/plotting/plot_test.py index 74340d5b..899c7d50 100644 --- a/tests/plotting/plot_test.py +++ b/tests/plotting/plot_test.py @@ -376,3 +376,24 @@ def test_plot_pandas_dataframe(): assert p.canvas.units['x'] == 'dimensionless' assert p.canvas.units['y'] == 'dimensionless' assert len(p._view.artists) == 4 + + +def test_hide_legend(): + da1 = data_array(ndim=1) + da2 = da1 * 3.3 + p = pp.plot({'a': da1, 'b': da2}, legend=False) + leg = p.ax.get_legend() + assert leg is None + + +def test_legend_location(): + da1 = data_array(ndim=1) + da2 = da1 * 3.3 + data = {'a': da1, 'b': da2} + leg1 = pp.plot(data, legend=(0.5, 0.5)).ax.get_legend().get_window_extent().bounds + leg2 = pp.plot(data, legend=(0.9, 0.5)).ax.get_legend().get_window_extent().bounds + leg3 = pp.plot(data, legend=(0.5, 0.9)).ax.get_legend().get_window_extent().bounds + assert leg2[0] > leg1[0] + assert leg2[1] == leg1[1] + assert leg3[1] > leg1[1] + assert leg3[0] == leg1[0]