diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db78bbb5..bf8d05c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,4 +62,4 @@ Please use explicit commit messages. See [NumPy's development workflow] for inspiration. [code-review]: https://mtlynch.io/code-review-love/ -[NumPy's development workflow]: https://docs.scipy.org/doc/numpy/dev/gitwash/development_workflow.html +[NumPy's development workflow]: https://numpy.org/doc/stable/dev/development_workflow.html diff --git a/backtesting/_plotting.py b/backtesting/_plotting.py index 81044e44..0aa608a2 100644 --- a/backtesting/_plotting.py +++ b/backtesting/_plotting.py @@ -615,7 +615,8 @@ def __eq__(self, other): for f in plots: if f.legend: - f.legend.location = 'top_left' if show_legend else None + f.legend.visible = show_legend + f.legend.location = 'top_left' f.legend.border_line_width = 1 f.legend.border_line_color = '#333333' f.legend.padding = 5 diff --git a/backtesting/test/_test.py b/backtesting/test/_test.py index b45f9824..ab905481 100644 --- a/backtesting/test/_test.py +++ b/backtesting/test/_test.py @@ -642,6 +642,14 @@ def test_params(self): with self.subTest(param=p[0]): bt.plot(**dict([p]), filename=f, open_browser=False) + def test_hide_legend(self): + bt = Backtest(GOOG.iloc[:100], SmaCross) + bt.run() + with _tempfile() as f: + bt.plot(filename=f, show_legend=False) + # Give browser time to open before tempfile is removed + time.sleep(5) + def test_resolutions(self): with _tempfile() as f: for rule in 'LSTHDWM':