mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
* quick econ fix * black * keys and feature flags * terminal name 👀 * some more replacements * some more replacements * edit pyproject * gst -> openbb * add example portfolios back to git * Update api from gst * sorry. skipping some tests * another round of names * another round of test edits * Missed some .gst refs and update timezone * water mark stuff * Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS * fix more GST to OpenBB Terminal * Logging : merge conflicts with main * Revert wrong files Co-authored-by: Andrew <andrew.kenreich@gmail.com> Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
"""Custom Controller View"""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
import os
|
|
from typing import List, Optional
|
|
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
|
|
from openbb_terminal.config_plot import PLOT_DPI
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import export_data, plot_autoscale
|
|
from openbb_terminal.config_terminal import theme
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def custom_plot(
|
|
data: pd.DataFrame,
|
|
y_col: str,
|
|
x_col: str = "",
|
|
kind: str = "line",
|
|
export: str = "",
|
|
external_axes: Optional[List[plt.Axes]] = None,
|
|
):
|
|
"""Plot custom data
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.DataFrame
|
|
Dataframe of custom data
|
|
y_col: str
|
|
Column for y data
|
|
x_col: str
|
|
Column for x data. Uses index if not supplied.
|
|
kind : str
|
|
Kind of plot to pass to pandas plot function
|
|
export: str
|
|
Format to export image
|
|
external_axes: Optional[List[plt.Axes]]:
|
|
External axes for plot
|
|
"""
|
|
if external_axes is None:
|
|
_, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
else:
|
|
ax = external_axes[0]
|
|
|
|
if x_col:
|
|
data.plot(x=x_col, y=y_col, kind=kind, ax=ax)
|
|
else:
|
|
data.reset_index().plot(x=data.index.name, y=y_col, kind=kind, ax=ax)
|
|
|
|
if kind in ["scatter", "line"]:
|
|
theme.style_primary_axis(ax)
|
|
theme.visualize_output()
|
|
|
|
export_data(
|
|
export,
|
|
os.path.dirname(os.path.abspath(__file__)),
|
|
"custom_plot",
|
|
)
|