Skip to content

Comparison Charts

Parallel Coordinates

Coming soon!

Scatter

src.dx.plotting.dex.basic_charts.scatter(df, x, y, size=None, trend_line=None, marginal_graphics=None, formula_display=None, return_view=False, **kwargs)

Generates a DEX scatterplot from the given DataFrame.

Parameters:

Name Type Description Default
df DataFrame

The DataFrame to plot.

required
x str

The column to use for the x-axis.

required
y str

The column to use for the y-axis.

required
size Optional[str]

The column to use for sizing scatterplot points.

None
trend_line Optional[DEXTrendlineType]

The type of trendline to use. One of "linear", "exponential", "polynomial", "power", or "logarithmic".

None
marginal_graphics Optional[DEXSummaryType]

The marginal graphics to use: - boxplot - heatmap - histogram - horizon - joy - ridgeline - violin

None
formula_display Optional[DEXFormulaDisplay]

The formula display to use: - r2 - formula

None
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 scatter(
    df: pd.DataFrame,
    x: str,
    y: str,
    size: Optional[str] = None,
    trend_line: Optional[options.DEXTrendlineType] = None,
    marginal_graphics: Optional[options.DEXSummaryType] = None,
    formula_display: Optional[options.DEXFormulaDisplay] = None,
    return_view: bool = False,
    **kwargs,
) -> Optional[DEXScatterChartView]:
    """
    Generates a DEX scatterplot from the given DataFrame.

    Parameters
    ----------
    df: pd.DataFrame
        The DataFrame to plot.
    x: str
        The column to use for the x-axis.
    y: str
        The column to use for the y-axis.
    size: Optional[str]
        The column to use for sizing scatterplot points.
    trend_line: Optional[DEXTrendlineType]
        The type of trendline to use. One of `"linear"`, `"exponential"`, `"polynomial"`, `"power"`, or `"logarithmic"`.
    marginal_graphics: Optional[DEXSummaryType]
        The marginal graphics to use:
            - `boxplot`
            - `heatmap`
            - `histogram`
            - `horizon`
            - `joy`
            - `ridgeline`
            - `violin`
    formula_display: Optional[DEXFormulaDisplay]
        The formula display to use:
            - `r2`
            - `formula`
    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, y], df.columns)

    chart_settings = {
        "metric1": x,
        "metric2": y,
    }
    # if these are present but set to `None`, DEX gets angry
    if trend_line is not None:
        chart_settings["trendLine"] = trend_line
    if size is not None:
        chart_settings["scatterplotSize"] = size
    if marginal_graphics is not None:
        chart_settings["marginalGraphics"] = marginal_graphics
    if formula_display is not None:
        chart_settings["formulaDisplay"] = formula_display

    return handle_view(
        df,
        chart_mode="scatter",
        chart=chart_settings,
        return_view=return_view,
        **kwargs,
    )

Connected Scatterplot

Coming soon!

Scatterplot Matrix

Coming soon!

Correlation Matrix

Coming soon!

Bar

src.dx.plotting.dex.basic_charts.bar(df, x, y, y2=None, y2_style='bar', horizontal=False, bar_width=None, group_other=False, column_sort_order='asc', column_sort_type='string', pro_bar_mode='combined', combination_mode='avg', show_bar_labels=False, return_view=False, **kwargs)

Generates a DEX bar 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 str

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

required
y2 Optional[str]

The column to use for the secondary y-axis.

None
y2_style DEXSecondMetricstyle

The style to use for the secondary y-axis. ("bar" or "dot")

'bar'
horizontal bool

Whether to plot the bars horizontally.

False
bar_width Optional[str]

The column to use for the bar width.

None
group_other bool

Whether to group the remaining columns into an "Other" category.

False
column_sort_order DEXSortColumnsByOrder

The order to sort the columns by ("asc" or "desc")

'asc'
column_sort_type DEXSortColumnsByType

The type of sorting to use. ("number", "string", or "date")

'string'
pro_bar_mode DEXProBarModeType

The bar mode to use ("clustered", "combined", or "stacked").

'combined'
combination_mode DEXCombinationMode

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

'avg'
show_bar_labels bool

Whether to show the bar values as labels.

False
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 bar(
    df,
    x: str,
    y: str,
    y2: Optional[str] = None,
    y2_style: options.DEXSecondMetricstyle = "bar",
    horizontal: bool = False,
    bar_width: Optional[str] = None,
    group_other: bool = False,
    column_sort_order: options.DEXSortColumnsByOrder = "asc",
    column_sort_type: options.DEXSortColumnsByType = "string",
    pro_bar_mode: options.DEXProBarModeType = "combined",
    combination_mode: options.DEXCombinationMode = "avg",
    show_bar_labels: bool = False,
    return_view: bool = False,
    **kwargs,
) -> Optional[DEXBarChartView]:
    """
    Generates a DEX bar plot from the given DataFrame.

    Parameters
    ----------
    df: pd.DataFrame
        The DataFrame to plot.
    x: str
        The column to use for the x-axis.
    y: List[str]
        The column(s) to use for the primary y-axis.
    y2: Optional[str]
        The column to use for the secondary y-axis.
    y2_style: DEXSecondMetricstyle
        The style to use for the secondary y-axis. (`"bar"` or `"dot"`)
    horizontal: bool
        Whether to plot the bars horizontally.
    bar_width: Optional[str]
        The column to use for the bar width.
    group_other: bool
        Whether to group the remaining columns into an "Other" category.
    column_sort_order: DEXSortColumnsByOrder
        The order to sort the columns by (`"asc"` or `"desc"`)
    column_sort_type: DEXSortColumnsByType
        The type of sorting to use. (`"number"`, `"string"`, or `"date"`)
    pro_bar_mode: DEXProBarModeType
        The bar mode to use (`"clustered"`, `"combined"`, or `"stacked"`).
    combination_mode: DEXCombinationMode
        The combination mode to use (`"avg"`, `"sum"`, `"min"`, `"median"`, `"max"`, or `"count"`).
    show_bar_labels: bool
        Whether to show the bar values as labels.
    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 not isinstance(y, list):
        y = [y]
    raise_for_missing_columns(y, df.columns)
    y1 = y[0]

    chart_settings = {
        "dim1": x,
        "metric1": y1,
        "bar_projection": "horizontal" if horizontal else "vertical",
        "sort_columns_by": f"{column_sort_order}-col-{column_sort_type}",
        "group_other": group_other,
        "combination_mode": combination_mode,
        "bar_label": "show" if show_bar_labels else "none",
        "selected_bar_metrics": y,
    }
    if bar_width is not None:
        chart_settings["metric3"] = bar_width
    if y2 is not None:
        chart_settings["second_bar_metric"] = y2
        chart_settings["pro_bar_mode"] = pro_bar_mode
        chart_settings["second_metric_style"] = y2_style

    return handle_view(
        df,
        chart_mode="bar",
        chart=chart_settings,
        return_view=return_view,
        **kwargs,
    )

Dot Plot

Coming soon!

Radar Plot

Coming soon!

Diverging Bar

Coming soon!