add use ion to plots so it doesn't hang (#1081)

This commit is contained in:
Didier Rodrigues Lopes
2021-12-22 15:12:48 +00:00
committed by GitHub
parent 8c84ff2831
commit e89f257bef
9 changed files with 50 additions and 35 deletions

View File

@@ -19,6 +19,7 @@ from gamestonk_terminal.common.behavioural_analysis.sentimentinvestor_model impo
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal.helper_funcs import plot_autoscale
from gamestonk_terminal import feature_flags as gtff
sentipy: Sentipy = Sentipy(
token=cfg.API_SENTIMENTINVESTOR_TOKEN, key=cfg.API_SENTIMENTINVESTOR_KEY
@@ -179,7 +180,8 @@ def display_historical(
# add title e.g. AAPL sentiment since 22/07/21
plt.title(f"{ticker} {metric} since {min(df.date).strftime('%x')}")
if gtff.USE_ION:
plt.ion()
plt.show()
###

View File

@@ -94,9 +94,6 @@ def display_defi_tvl(top: int, export: str = "") -> None:
df = df.tail(top)
df["totalLiquidityUSD"] = df["totalLiquidityUSD"] / 1_000_000_000
if gtff.USE_ION:
plt.ion()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df["date"], df["totalLiquidityUSD"], "-ok", ms=2)
@@ -108,6 +105,8 @@ def display_defi_tvl(top: int, export: str = "") -> None:
plt.minorticks_on()
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
plt.title("Total Value Locked in DeFi [Billions USD]")
if gtff.USE_ION:
plt.ion()
plt.show()
print("")

View File

@@ -7,6 +7,7 @@ from gamestonk_terminal.cryptocurrency.due_diligence.coinglass_model import (
)
from gamestonk_terminal.helper_funcs import export_data, plot_autoscale
from gamestonk_terminal import config_plot as cfgPlot
from gamestonk_terminal import feature_flags as gtff
def display_open_interest(symbol: str, interval: int, export: str) -> None:
@@ -60,4 +61,7 @@ def plot_data(df: pd.DataFrame, symbol: str):
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.gcf().autofmt_xdate()
if gtff.USE_ION:
plt.ion()
plt.show()

View File

@@ -8,6 +8,7 @@ from gamestonk_terminal.cryptocurrency.due_diligence.glassnode_model import (
get_exchange_balances,
get_exchange_net_position_change,
)
from gamestonk_terminal import feature_flags as gtff
def display_active_addresses(
@@ -49,6 +50,9 @@ def display_active_addresses(
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.gcf().autofmt_xdate()
if gtff.USE_ION:
plt.ion()
plt.show()
print("")
@@ -118,6 +122,9 @@ def display_exchange_net_position_change(
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=3))
plt.gcf().autofmt_xdate()
if gtff.USE_ION:
plt.ion()
plt.show()
print("")
@@ -185,6 +192,9 @@ def display_exchange_balances(
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=3))
plt.gcf().autofmt_xdate()
if gtff.USE_ION:
plt.ion()
plt.show()
print("")

View File

@@ -442,7 +442,7 @@ Graphs:
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="ret",
prog="rmr",
description="Graph of portfolio returns versus market returns",
)
parser.add_argument(

View File

@@ -12,6 +12,7 @@ from sklearn.preprocessing import normalize
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal.helper_funcs import plot_autoscale
from gamestonk_terminal import feature_flags as gtff
d_candle_types = {
"o": "Open",
@@ -121,6 +122,8 @@ def get_sp500_comps_tsne(
ax.scatter(x, y, s=50, c="r")
ax.annotate(company, (x, y), fontsize=9, alpha=1)
fig.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
data = pd.DataFrame({"X": xs, "Y": ys}, index=rets.index)
x0, y0 = data.loc[ticker]

View File

@@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import (
long_number_format,
export_data,
)
from gamestonk_terminal import feature_flags as gtff
def plot_short_interest(ticker: str, nyse: bool, df_short_interest: pd.DataFrame):
@@ -58,6 +59,9 @@ def plot_short_interest(ticker: str, nyse: bool, df_short_interest: pd.DataFrame
plt.xlim([df_short_interest.index[0], df_short_interest.index[-1]])
plt.gcf().autofmt_xdate()
if gtff.USE_ION:
plt.ion()
plt.show()

View File

@@ -277,21 +277,19 @@ def plot_oi(
ls="-",
c="g",
)
ax.axvline(
current_price, lw=2, c="k", ls="--", label="Current Price", alpha=0.7
)
ax.axvline(max_pain, lw=3, c="k", label=f"Max Pain: {max_pain}", alpha=0.7)
ax.grid("on")
ax.set_xlabel("Strike Price")
ax.set_ylabel("Open Interest (1k) ")
ax.set_xlim(min_strike, max_strike)
ax.axvline(current_price, lw=2, c="k", ls="--", label="Current Price", alpha=0.7)
ax.axvline(max_pain, lw=3, c="k", label=f"Max Pain: {max_pain}", alpha=0.7)
ax.grid("on")
ax.set_xlabel("Strike Price")
ax.set_ylabel("Open Interest (1k) ")
ax.set_xlim(min_strike, max_strike)
if gtff.USE_ION:
plt.ion()
if gtff.USE_ION:
plt.ion()
ax.set_title(f"Open Interest for {ticker.upper()} expiring {expiry}")
plt.legend(loc=0)
fig.tight_layout(pad=1)
ax.set_title(f"Open Interest for {ticker.upper()} expiring {expiry}")
plt.legend(loc=0)
fig.tight_layout(pad=1)
plt.show()
export_data(

View File

@@ -137,8 +137,6 @@ def display_bars_financials(
print(df.to_string, "\n")
else:
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
magnitude = 0
while max(company_metric) > 1_000 or abs(min(company_metric)) > 1_000:
@@ -204,6 +202,8 @@ def display_bars_financials(
)
plt.title(title)
if gtff.USE_ION:
plt.ion()
plt.tight_layout()
plt.show()
@@ -355,8 +355,6 @@ def display_companies_per_sector_in_country(
legend, values = zip(*companies_per_sector.items())
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
plt.pie(
values,
labels=legend,
@@ -367,7 +365,8 @@ def display_companies_per_sector_in_country(
)
plt.title(title)
plt.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
elif len(companies_per_sector) == 1:
@@ -521,8 +520,6 @@ def display_companies_per_industry_in_country(
legend, values = zip(*companies_per_industry.items())
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
plt.pie(
values,
labels=legend,
@@ -533,7 +530,8 @@ def display_companies_per_industry_in_country(
)
plt.title(title)
plt.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
elif len(companies_per_industry) == 1:
@@ -685,8 +683,6 @@ def display_companies_per_industry_in_sector(
legend, values = zip(*companies_per_industry.items())
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
plt.pie(
values,
labels=legend,
@@ -697,7 +693,8 @@ def display_companies_per_industry_in_sector(
)
plt.title(title)
plt.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
elif len(companies_per_industry) == 1:
@@ -847,8 +844,6 @@ def display_companies_per_country_in_sector(
legend, values = zip(*companies_per_country.items())
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
plt.pie(
values,
labels=legend,
@@ -859,7 +854,8 @@ def display_companies_per_country_in_sector(
)
plt.title(title)
plt.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
elif len(companies_per_country) == 1:
@@ -1009,8 +1005,6 @@ def display_companies_per_country_in_industry(
legend, values = zip(*companies_per_country.items())
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
if gtff.USE_ION:
plt.ion()
plt.pie(
values,
labels=legend,
@@ -1021,7 +1015,8 @@ def display_companies_per_country_in_industry(
)
plt.title(title)
plt.tight_layout()
if gtff.USE_ION:
plt.ion()
plt.show()
elif len(companies_per_country) == 1: