Skip to content

Time Series Charts

Line

src.dx.plotting.dex.basic_charts.line(df, x, y, line_type='line', split_by=None, multi_axis=False, smoothing=None, use_count=False, bounding_type='absolute', zero_baseline=False, combination_mode='avg', return_view=False, **kwargs)

Generates a DEX line plot from the given DataFrame.

Parameters:

Name Type Description Default
df

The DataFrame to plot.

required
x str

The column to use for the x-axis.

required
y Union[List[str], str]

The column(s) to use for the y-axis.

required
line_type DEXLineType

The line type to use: - "bumparea" - "cumulative" - "line" (default) - "linepercent" - "stackedarea" - "stackedpercent"

'line'
split_by Optional[str]

The column to use for splitting the lines.

None
multi_axis bool

Whether to use multiple y-axes.

False
smoothing Optional[DEXLineSmoothing]

The line smoothing to use: - None (default) - "hourly" - "daily" - "weekly" - "seven_day_moving_average" - "monthly"

None
use_count bool

Whether to use the DEX_COUNT column for the y-axis.

False
bounding_type DEXBoundingType

The bounding type to use: - "absolute" (default) - "relative"

'absolute'
zero_baseline bool

Whether to use a zero base line.

False
combination_mode DEXCombinationMode

The combination mode to use ("avg", "sum", "min", "median", "max", or "count").

'avg'
return_view bool

Whether to return a DEXView object instead of render.

False
**kwargs

Additional keyword arguments to pass to the view metadata.

{}
Source code in src/dx/plotting/dex/basic_charts.py
def line(
    df,
    x: str,
    y: Union[List[str], str],
    line_type: options.DEXLineType = "line",
    split_by: Optional[str] = None,
    multi_axis: bool = False,
    smoothing: Optional[options.DEXLineSmoothing] = None,
    use_count: bool = False,
    bounding_type: options.DEXBoundingType = "absolute",
    zero_baseline: bool = False,
    combination_mode: options.DEXCombinationMode = "avg",
    return_view: bool = False,
    **kwargs,
) -> Optional[DEXLineChartView]:
    """
    Generates a DEX line plot from the given DataFrame.

    Parameters
    ----------
    df: pd.DataFrame
        The DataFrame to plot.
    x: str
        The column to use for the x-axis.
    y: Union[List[str], str]
        The column(s) to use for the y-axis.
    line_type: DEXLineType
        The line type to use:
            - `"bumparea"`
            - `"cumulative"`
            - `"line"` (default)
            - `"linepercent"`
            - `"stackedarea"`
            - `"stackedpercent"`
    split_by: Optional[str]
        The column to use for splitting the lines.
    multi_axis: bool
        Whether to use multiple y-axes.
    smoothing: Optional[DEXLineSmoothing]
        The line smoothing to use:
            - `None` (default)
            - `"hourly"`
            - `"daily"`
            - `"weekly"`
            - `"seven_day_moving_average"`
            - `"monthly"`
    use_count: bool
        Whether to use the DEX_COUNT column for the y-axis.
    bounding_type: DEXBoundingType
        The bounding type to use:
            - `"absolute"` (default)
            - `"relative"`
    zero_baseline: bool
        Whether to use a zero base line.
    combination_mode: DEXCombinationMode
        The combination mode to use (`"avg"`, `"sum"`, `"min"`, `"median"`, `"max"`, or `"count"`).
    return_view: bool
        Whether to return a `DEXView` object instead of render.
    **kwargs
        Additional keyword arguments to pass to the view metadata.
    """
    raise_for_missing_columns(x, df.columns)

    if isinstance(y, str):
        y = [y]
    raise_for_missing_columns(y, df.columns)
    if use_count:
        y.append("DEX_COUNT")

    if split_by is not None:
        if str(split_by) not in df.columns:
            raise ValueError(f"Column '{split_by}' not found in DataFrame.")

    chart_settings = {
        "bounding_type": bounding_type,
        "combination_mode": combination_mode,
        "line_smoothing": smoothing or "none",
        "line_type": line_type,
        "multi_axis_line": multi_axis,
        "selected_metrics": y,
        "split_lines_by": split_by,
        "timeseries_sort": x,
        "zero_baseline": zero_baseline,
    }
    logger.debug(f"{chart_settings=}")
    return handle_view(
        df,
        chart_mode="line",
        chart=chart_settings,
        return_view=return_view,
        **kwargs,
    )

Cumulative

Coming soon!

Stacked Area

Coming soon!

Line Percent

Coming soon!

Stacked Percent

Coming soon!

Candlestick

Coming soon!