Remove matplotlib references (#4479)

* remove theme refs

* will come for dtabento later

* remove theme refs except databento

* ruff

* remove mpl variables

* mpl still used in po

* move databento to plotly

* pylint

* ruff

* theme ref to openbb_terminal

* juans sugg

* fix: removed raw arg in `display_candle` which could return the dataframe and error, added figure to `export_data`

---------

Co-authored-by: teh_coderer <me@tehcoderer.com>
This commit is contained in:
montezdesousa
2023-03-15 14:25:59 +00:00
committed by GitHub
parent 8bd7606120
commit b19dc5205d
37 changed files with 64 additions and 140 deletions

View File

@@ -7,9 +7,8 @@ from typing import Optional, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.alternative.covid import covid_model
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console

View File

@@ -7,9 +7,8 @@ from typing import List, Optional, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.common.behavioural_analysis import google_model
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table

View File

@@ -9,9 +9,8 @@ import numpy as np
import pandas as pd
from dateutil import parser as dparse
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.common.behavioural_analysis import twitter_model
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, get_closing_price
from openbb_terminal.rich_config import console

View File

@@ -18,9 +18,8 @@ from pandas.plotting import register_matplotlib_converters
from scipy import stats
from statsmodels.graphics.gofplots import qqplot
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.common.quantitative_analysis import qa_model
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console

View File

@@ -79,12 +79,10 @@ class PreferencesModel:
MONITOR: NonNegativeInt = 0
# STYLE
# Color for `view` command data. All pyplot colors listed at:
# https://matplotlib.org/stable/gallery/color/named_colors.html
VIEW_COLOR: str = "tab:green"
MPL_STYLE: str = "dark"
PMF_STYLE: str = "dark"
RICH_STYLE: str = "dark"
PLOT_STYLE: str = "dark"
# PATHS
PREFERRED_DATA_SOURCE_FILE: str = str(USER_DATA_SOURCES_DEFAULT_FILE)

View File

@@ -212,7 +212,9 @@ class TerminalStyle:
return colors
theme = TerminalStyle("dark", "dark")
theme = TerminalStyle(
get_current_user().preferences.PLOT_STYLE, get_current_user().preferences.RICH_STYLE
)
theme.apply_style()

View File

@@ -8,10 +8,9 @@ from typing import Any, Dict, List, Optional, Type, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.base_helpers import console
from openbb_terminal.common.technical_analysis import ta_helpers
from openbb_terminal.config_terminal import theme
from openbb_terminal.core.plots.plotly_ta.base import PltTA
from openbb_terminal.core.plots.plotly_ta.data_classes import ChartIndicators

View File

@@ -336,7 +336,7 @@ import logging
import openbb_terminal.config_terminal as cfg
from openbb_terminal import helper_funcs as helper # noqa: F401
from openbb_terminal.config_terminal import theme
from openbb_terminal.core.plots.plotly_helper import theme # noqa: F401
from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import Coin
from openbb_terminal.dashboards.dashboards_controller import DashboardsController

View File

@@ -5,10 +5,7 @@ import logging
import os
from typing import Optional, Union
from openbb_terminal import (
OpenBBFigure,
config_terminal as cfg,
)
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.cryptocurrency_helpers import read_data_file
from openbb_terminal.cryptocurrency.defi import llama_model
from openbb_terminal.decorators import log_start_end
@@ -46,7 +43,7 @@ def display_grouped_defi_protocols(
)
fig.set_title(f"Top {limit} dApp TVL grouped by chain")
colors = iter(cfg.theme.get_colors(reverse=True))
colors = iter(theme.get_colors(reverse=True))
for chain in chains:
chain_filter = df.loc[df.Chain == chain]

View File

@@ -4,8 +4,7 @@ from typing import Optional, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.due_diligence.coinglass_model import (
get_funding_rate,
get_liquidations,

View File

@@ -8,12 +8,11 @@ from typing import Optional, Union
import numpy as np
import pandas as pd
from openbb_terminal import OpenBBFigure, rich_config
from openbb_terminal import OpenBBFigure, rich_config, theme
from openbb_terminal.common.behavioural_analysis.finbrain_model import get_sentiment
from openbb_terminal.common.behavioural_analysis.finbrain_view import (
lambda_sentiment_coloring,
)
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data
from openbb_terminal.rich_config import console

View File

@@ -5,8 +5,7 @@ from typing import Optional, Union
import numpy as np
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.due_diligence.glassnode_model import (
get_active_addresses,
get_exchange_balances,

View File

@@ -11,8 +11,7 @@ from typing import Optional, Union
import numpy as np
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency import cryptocurrency_helpers
from openbb_terminal.cryptocurrency.dataframe_helpers import prettify_paragraph
from openbb_terminal.cryptocurrency.due_diligence.messari_model import (

View File

@@ -7,8 +7,7 @@ import logging
import os
from typing import Optional, Union
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.nft import nftpricefloor_model
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table

View File

@@ -5,8 +5,7 @@ import logging
import os
from typing import Optional, Union
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.onchain.shroom_model import (
get_daily_transactions,
get_dapp_stats,

View File

@@ -4,8 +4,7 @@ import os
from datetime import datetime
from typing import Optional, Union
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.overview.blockchaincenter_model import (
DAYS,
get_altcoin_index,

View File

@@ -6,8 +6,7 @@ from typing import Optional
import numpy as np
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.overview.glassnode_model import get_btc_rainbow
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import export_data

View File

@@ -5,10 +5,7 @@ from typing import Optional, Union
import pandas as pd
from openbb_terminal import (
OpenBBFigure,
config_terminal as cfg,
)
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.overview import loanscan_model
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
@@ -63,7 +60,7 @@ def display_crypto_rates(
df_non_null = pd.melt(df.reset_index(), id_vars=["index"]).dropna()
assets = df_non_null.variable.unique().tolist()
colors = iter(cfg.theme.get_colors(reverse=True))
colors = iter(theme.get_colors(reverse=True))
for asset in assets:
width = df_non_null.loc[(df_non_null.variable == asset)]

View File

@@ -2,10 +2,7 @@
import logging
import os
from openbb_terminal import (
OpenBBFigure,
config_terminal as cfg,
)
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.cryptocurrency.overview.tokenterminal_model import (
CATEGORIES,
METRICS,
@@ -77,7 +74,7 @@ def display_fundamental_metrics(
fig.add_bar(
x=metric_series[:limit].index,
y=metric_series[:limit].values,
marker_color=cfg.theme.get_colors(reverse=True)[:limit],
marker_color=theme.get_colors(reverse=True)[:limit],
)
if category:

View File

@@ -5,8 +5,7 @@ import logging
import os
from typing import Optional, Union
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.economy import alphavantage_model
from openbb_terminal.helper_funcs import export_data, print_rich_table

View File

@@ -7,8 +7,7 @@ from typing import Optional
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.etf import fmp_model
from openbb_terminal.helper_funcs import (

View File

@@ -6,8 +6,7 @@ from typing import Dict, Optional, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.core.plots.plotly_ta.ta_class import PlotlyTA
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.forex.oanda.oanda_model import (

View File

@@ -1,24 +1,23 @@
"""DataBento view"""
__docformat__ = "numpy"
import logging
import os
from typing import List, Optional
from typing import Optional
import mplfinance as mpf
from matplotlib import pyplot as plt
from openbb_terminal.config_terminal import theme
from openbb_terminal.core.plots.plotly_helper import OpenBBFigure
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import (
export_data,
is_valid_axes_count,
lambda_long_number_format_y_axis,
plot_autoscale,
print_rich_table,
)
from openbb_terminal.rich_config import console
from openbb_terminal.stocks import databento_model
from openbb_terminal.stocks import databento_model, stocks_helper
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def display_historical(
symbol: str,
start_date: Optional[str] = None,
@@ -26,8 +25,8 @@ def display_historical(
raw: bool = False,
export: str = "",
sheet_name: Optional[str] = None,
external_axes: Optional[List[plt.Axes]] = None,
):
external_axes: bool = False,
) -> Optional[OpenBBFigure]:
"""Display historical futures [Source: DataBento]
Parameters
@@ -44,61 +43,21 @@ def display_historical(
Optionally specify the name of the sheet the data is exported to.
export: str
Type of format to export data
external_axes : Optional[List[plt.Axes]], optional
External axes (1 axis is expected in the list), by default None
external_axes : bool, optional
Whether to return the figure object or not, by default False
"""
data = databento_model.get_historical_futures(
symbol.upper(), start_date=start_date, end_date=end_date
)
if data.empty:
console.print(f"No data found for {symbol}.")
return
# We check if there's Volume data to avoid errors and empty subplots
has_volume = False
if "Volume" in data.columns:
has_volume = bool(data["Volume"].sum() > 0)
return console.print(f"No data found for {symbol}.")
candle_chart_kwargs = {
"type": "candle",
"style": theme.mpf_style,
"volume": has_volume,
"addplot": [],
"xrotation": theme.xticks_rotation,
"scale_padding": {"left": 0.3, "right": 1, "top": 0.8, "bottom": 0.8},
"update_width_config": {
"candle_linewidth": 0.6,
"candle_width": 0.8,
"volume_linewidth": 0.8,
"volume_width": 0.8,
},
"warn_too_much_data": 10000,
}
if external_axes is None:
candle_chart_kwargs["returnfig"] = True
candle_chart_kwargs["figratio"] = (10, 7)
candle_chart_kwargs["figscale"] = 1.10
candle_chart_kwargs["figsize"] = plot_autoscale()
candle_chart_kwargs["warn_too_much_data"] = 100_000
fig, ax = mpf.plot(data, **candle_chart_kwargs)
if has_volume:
lambda_long_number_format_y_axis(data, "Volume", ax)
fig.suptitle(
f"{symbol}",
x=0.055,
y=0.965,
horizontalalignment="left",
)
theme.visualize_output(force_tight_layout=False)
elif (has_volume and is_valid_axes_count(external_axes, 2)) or (
not has_volume and is_valid_axes_count(external_axes, 1)
):
candle_chart_kwargs["ax"] = external_axes[0]
if has_volume:
candle_chart_kwargs["volume"] = external_axes[1]
mpf.plot(data, **candle_chart_kwargs)
data = stocks_helper.process_candle(data)
figure = stocks_helper.display_candle(
symbol=symbol,
data=data,
external_axes=True,
)
if raw:
print_rich_table(
@@ -106,6 +65,7 @@ def display_historical(
headers=list(data.columns),
show_index=True,
title="Futures timeseries",
export=bool(export),
)
console.print()
@@ -115,4 +75,7 @@ def display_historical(
"historical_db",
data,
sheet_name,
figure,
)
return figure.show(external=external_axes) # type: ignore

View File

@@ -22,7 +22,6 @@ from prompt_toolkit.styles import Style
from rich.markdown import Markdown
# IMPORTS INTERNAL
from openbb_terminal.config_terminal import theme
from openbb_terminal.core.completer.choices import build_controller_choice_map
from openbb_terminal.core.session.constants import REGISTER_URL
from openbb_terminal.core.session.current_user import get_current_user, is_local
@@ -156,8 +155,6 @@ class BaseController(metaclass=ABCMeta):
self.parser.exit_on_error = False # type: ignore
self.parser.add_argument("cmd", choices=self.controller_choices)
theme.applyMPLstyle()
# Add in about options
self.ABOUT_CHOICES = {
c: None for c in self.CHOICES_COMMANDS + self.CHOICES_MENUS

View File

@@ -16,6 +16,7 @@ from openbb_terminal import (
config_terminal as cfg,
)
from openbb_terminal.core.config.paths import MISCELLANEOUS_DIRECTORY
from openbb_terminal.core.plots.plotly_helper import theme
from openbb_terminal.core.session.current_user import get_current_user
# pylint: disable=no-member,c-extension-no-member
@@ -24,7 +25,7 @@ from openbb_terminal.core.session.current_user import get_current_user
# https://rich.readthedocs.io/en/stable/appendix/colors.html#appendix-colors
# https://rich.readthedocs.io/en/latest/highlighting.html#custom-highlighters
CUSTOM_THEME = Theme(cfg.theme.console_style)
CUSTOM_THEME = Theme(theme.console_style)
RICH_TAGS = [
"[menu]",

View File

@@ -7,7 +7,7 @@ import logging
import openbb_terminal.config_terminal as cfg
from openbb_terminal import helper_funcs as helper # noqa: F401
from openbb_terminal.config_terminal import theme
from openbb_terminal.core.plots.plotly_helper import theme # noqa: F401
from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import Coin
from openbb_terminal.dashboards.dashboards_controller import DashboardsController
@@ -27,7 +27,6 @@ cfg.start_required_configurations()
cfg.start_plot_backend()
logger = logging.getLogger(__name__)
theme.applyMPLstyle()
class OpenBBSDK:

View File

@@ -8,8 +8,7 @@ from typing import Optional, Union
import pandas as pd
import yfinance as yf
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import export_data
from openbb_terminal.stocks.behavioural_analysis import finnhub_model

View File

@@ -8,8 +8,7 @@ from typing import List, Optional
import numpy as np
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console

View File

@@ -10,8 +10,7 @@ import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.stocks.comparison_analysis import yahoo_finance_model

View File

@@ -7,8 +7,7 @@ from typing import Optional
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -7,8 +7,7 @@ from typing import Optional, Union
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -9,9 +9,8 @@ from typing import Optional, Union
from pandas.core.frame import DataFrame
from openbb_terminal import OpenBBFigure
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.common.technical_analysis import ta_helpers
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -8,8 +8,7 @@ from typing import Optional
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -9,8 +9,7 @@ from typing import Optional, Union
import pandas as pd
import yfinance as yf
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -8,8 +8,7 @@ from typing import Optional, Union
import numpy as np
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console

View File

@@ -9,8 +9,7 @@ from typing import Optional
import pandas as pd
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import (
export_data,

View File

@@ -6,8 +6,7 @@ import logging
import os
from typing import List, Optional, Union
from openbb_terminal import OpenBBFigure
from openbb_terminal.config_terminal import theme
from openbb_terminal import OpenBBFigure, theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console