Skip to content

Commit

Permalink
BUG: Fix plot show_legend = False (#207)
Browse files Browse the repository at this point in the history
* update NumPy's dev workflow url

* modified legend visibility and created a test func

* fixed linting error

* time.sleep(5)
  • Loading branch information
eervin123 authored Dec 24, 2020
1 parent bbcb7ba commit 1ee5670
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions backtesting/test/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 1ee5670

Please sign in to comment.