change where mpl backend import is changed

This commit is contained in:
Jamie
2021-04-30 15:59:37 -04:00
parent 1aefe96400
commit 933f3eba0a
4 changed files with 10 additions and 13 deletions

View File

@@ -11,10 +11,14 @@ from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.helper_funcs import get_flair
from gamestonk_terminal.menu import session
# This code below aims to fix an issue with the fnn module, used by bt module
# which forces matplotlib backend to be 'agg' which doesn't allow to plot
# Save current matplotlib backend
default_backend = mpl.get_backend()
# pylint: disable=wrong-import-position
from gamestonk_terminal.backtesting import bt_view # noqa: E402
# Restore backend matplotlib used
mpl.use(default_backend)

View File

@@ -9,21 +9,11 @@ from matplotlib import pyplot as plt
from pandas.plotting import register_matplotlib_converters
import bt
from gamestonk_terminal.helper_funcs import plot_autoscale
from gamestonk_terminal.config_plot import PLOT_DPI, backend
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
if backend is not None:
print(f"Setting matplotlib backend to {backend}")
matplotlib.use(backend)
if matplotlib.get_backend() in ["Agg", "MacOSX"]:
print(
"You may encounter errors due to your MatplotLib backend. "
" Please configure in config_plot.py."
)
def buy_and_hold(ticker: str, start: Union[str, datetime], name: str):
"""

View File

@@ -1,11 +1,11 @@
PLOT_DPI = 100
# Backend to use for plotting
backend = None
BACKEND = None
# Examples:
# "tkAgg" - This uses the tkinter library. If unsure, set to this
# "module://backend_interagg" - This is what pycharm defaults to in Scientific Mode
# "MacOSX" - Mac default. Does not work with backtesting
# "tkAgg" - This uses the tkinter library.
# "Qt5Agg" - This requires the PyQt5 package is installed
# See more: https://matplotlib.org/stable/tutorials/introductory/usage.html#the-builtin-backends

View File

@@ -6,6 +6,7 @@ import re
import sys
from pytz import timezone
import iso8601
import matplotlib
import matplotlib.pyplot as plt
from holidays import US as holidaysUS
from colorama import Fore, Style
@@ -17,6 +18,8 @@ from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal import config_plot as cfgPlot
register_matplotlib_converters()
if cfgPlot.BACKEND is not None:
matplotlib.use(cfgPlot.BACKEND)
def check_non_negative(value) -> int: