Loading...

verticapy.vDataFrame.bar#

vDataFrame.bar(columns: str | list[str], method: Literal['density', 'count', 'avg', 'min', 'max', 'sum'] | str = 'density', of: str | None = None, max_cardinality: tuple[int, int] = (6, 6), h: tuple[int | float | Decimal, int | float | Decimal] = (None, None), kind: Literal['auto', 'drilldown', 'stacked'] = 'auto', categoryorder: Literal['trace', 'category ascending', 'category descending', 'total ascending', 'total descending', 'min ascending', 'min descending', 'max ascending', 'max descending', 'sum ascending', 'sum descending', 'mean ascending', 'mean descending', 'median ascending', 'median descending'] = 'trace', chart: PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure | None = None, **style_kwargs) PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure#

Draws the bar chart of the input vDataColumns based on an aggregation.

Parameters#

columns: SQLColumns

list of the vDataColumns names.

method: str, optional

The method used to aggregate the data.

  • count:

    Number of elements.

  • density:

    Percentage of the distribution.

  • mean:

    Average of the vDataColumns of.

  • min:

    Minimum of the vDataColumns of.

  • max:

    Maximum of the vDataColumns of.

  • sum:

    Sum of the vDataColumns of.

  • q%:

    q Quantile of the vDataColumns of (ex: 50% to get the median).

It can also be a cutomized aggregation, for example: AVG(column1) + 5

of: str, optional

The vDataColumns used to compute the aggregation.

max_cardinality: tuple, optional

Maximum number of distinct elements for vDataColumns 1 and 2 to be used as categorical. For these elements, no h is picked or computed.

Important

This parameter is only used for categorical data types. For numerics use h to discretize them first

h: tuple, optional

Interval width of the vDataColumns 1 and 2 bars.

Important

Only valid if the vDataColumns are numerical. Optimized h will be computed if the parameter is empty or invalid.

kind: str, optional

The BarChart Type.

  • auto:

    Regular Bar Chart based on 1 or 2 vDataColumns.

  • drilldown:

    Drilldown Bar Chart.

  • pyramid:

    Pyramid Density Bar Chart. Only works if one of the two vDataColumns is binary and the method='density'.

  • stacked:

    Stacked Bar Chart based on 2 vDataColumns.

  • fully_stacked:

    Fully Stacked Bar Chart based on 2 vDataColumns.

categoryorder: str, optional

How to sort the bars. One of the following options:

  • trace (no transformation)

  • category ascending

  • category descending

  • total ascending

  • total descending

  • min ascending

  • min descending

  • max ascending

  • max descending

  • sum ascending

  • sum descending

  • mean ascending

  • mean descending

  • median ascending

  • median descending

chart: PlottingObject, optional

The chart object to plot on.

**style_kwargs

Any optional parameter to pass to the plotting functions.

Returns#

obj

Plotting Object.

Examples#

Note

The below example is a very basic one. For other more detailed examples and customization options, please see Bar Chart

Let’s begin by importing VerticaPy.

import verticapy as vp

Let’s also import numpy to create a dataset.

import numpy as np

Let’s generate a dataset using the following data.

data = vp.vDataFrame(
    {
        "gender": ['M', 'M', 'M', 'F', 'F', 'F', 'F'],
        "grade": ['A','B','C','A','B','B', 'B'],
    }
)

Below are examples of two types of bar plots:

  • 1D

  • 2D

data.bar(["grade"])
data.bar(columns = ["grade", "gender"])

See also

vDataFrame.barh() : Horizontal Bar Chart.
vDataColumn.bar() : Bar Chart.
vDataColumn.barh() : Horizontal Bar Chart.