Skip to content

Plot show_legend = False fix #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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