Skip to content

Commit 1ee5670

Browse files
authored
BUG: Fix plot show_legend = False (#207)
* update NumPy's dev workflow url * modified legend visibility and created a test func * fixed linting error * time.sleep(5)
1 parent bbcb7ba commit 1ee5670

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ Please use explicit commit messages. See [NumPy's development workflow]
6262
for inspiration.
6363

6464
[code-review]: https://mtlynch.io/code-review-love/
65-
[NumPy's development workflow]: https://docs.scipy.org/doc/numpy/dev/gitwash/development_workflow.html
65+
[NumPy's development workflow]: https://numpy.org/doc/stable/dev/development_workflow.html

backtesting/_plotting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ def __eq__(self, other):
615615

616616
for f in plots:
617617
if f.legend:
618-
f.legend.location = 'top_left' if show_legend else None
618+
f.legend.visible = show_legend
619+
f.legend.location = 'top_left'
619620
f.legend.border_line_width = 1
620621
f.legend.border_line_color = '#333333'
621622
f.legend.padding = 5

backtesting/test/_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ def test_params(self):
642642
with self.subTest(param=p[0]):
643643
bt.plot(**dict([p]), filename=f, open_browser=False)
644644

645+
def test_hide_legend(self):
646+
bt = Backtest(GOOG.iloc[:100], SmaCross)
647+
bt.run()
648+
with _tempfile() as f:
649+
bt.plot(filename=f, show_legend=False)
650+
# Give browser time to open before tempfile is removed
651+
time.sleep(5)
652+
645653
def test_resolutions(self):
646654
with _tempfile() as f:
647655
for rule in 'LSTHDWM':

0 commit comments

Comments
 (0)