diff --git a/src/plopp/backends/matplotlib/line.py b/src/plopp/backends/matplotlib/line.py index 4ecd1ce8..fa03143b 100644 --- a/src/plopp/backends/matplotlib/line.py +++ b/src/plopp/backends/matplotlib/line.py @@ -163,6 +163,11 @@ def _make_line( leg_args = {} if isinstance(self._canvas._legend, (list, tuple)): leg_args = {'loc': self._canvas._legend} + elif not isinstance(self._canvas._legend, bool): + raise TypeError( + "Legend must be a bool, tuple, or a list, " + f"not {type(self._canvas._legend)}" + ) self._ax.legend(**leg_args) def _make_data(self) -> dict: diff --git a/tests/plotting/plot_test.py b/tests/plotting/plot_test.py index 899c7d50..0fe53df7 100644 --- a/tests/plotting/plot_test.py +++ b/tests/plotting/plot_test.py @@ -397,3 +397,10 @@ def test_legend_location(): assert leg2[1] == leg1[1] assert leg3[1] > leg1[1] assert leg3[0] == leg1[0] + + +def test_hide_legend_bad_type(): + da1 = data_array(ndim=1) + da2 = da1 * 3.3 + with pytest.raises(TypeError, match='Legend must be a bool, tuple, or a list'): + pp.plot({'a': da1, 'b': da2}, legend='False')