From a18977486eb163923bb008b2b57f8fd11659954f Mon Sep 17 00:00:00 2001 From: Theodore Aptekarev Date: Tue, 22 Feb 2022 23:17:52 +0300 Subject: [PATCH] Fix hashrate chart legend position (#1406) Co-authored-by: didierlopes.eth --- .../cryptocurrency/due_diligence/glassnode_view.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/cryptocurrency/due_diligence/glassnode_view.py b/gamestonk_terminal/cryptocurrency/due_diligence/glassnode_view.py index d390ee4b5af..0002709122b 100644 --- a/gamestonk_terminal/cryptocurrency/due_diligence/glassnode_view.py +++ b/gamestonk_terminal/cryptocurrency/due_diligence/glassnode_view.py @@ -8,6 +8,7 @@ import numpy as np from matplotlib import dates as mdates from matplotlib import pyplot as plt from matplotlib import ticker +from matplotlib.lines import Line2D from gamestonk_terminal.config_terminal import theme from gamestonk_terminal import config_plot as cfgPlot @@ -494,7 +495,6 @@ def display_hashrate( ax1.yaxis.set_major_formatter(ticker.StrMethodFormatter("{x:.0f}T")) ax1.set_ylabel(f"{asset} hashrate (Terahashes/second)") ax1.set_title(f"{asset}: Mean hashrate") - ax1.legend(["Hash Rate"], loc="best") ax1.tick_params(axis="x", labelrotation=10) ax2.set_xlim(left=df.index[0]) @@ -502,7 +502,14 @@ def display_hashrate( ax2.plot(df.index, df["price"] / 1_000, color=theme.up_color, lw=0.8) ax2.yaxis.set_major_formatter(ticker.StrMethodFormatter("${x:.1f}k")) ax2.set_ylabel(f"{asset} price [$]") - ax2.legend(["Price"], loc="best") + + # Manually construct the chart legend + lines = [ + Line2D([0], [0], color=color) + for color in [theme.up_color, theme.down_color] + ] + labels = ["Hash Rate", "Price"] + ax2.legend(lines, labels) if not external_axes: theme.visualize_output()