Quantile Transform

The quantile transform calculates empirical quantile values for input data. If a groupby parameter is provided, quantiles are estimated separately per group. Among other uses, the quantile transform is useful for creating quantile-quantile (Q-Q) plots.

Here is an example of a quantile plot of normally-distributed data:

import altair as alt
import pandas as pd
import numpy as np

np.random.seed(42)
df = pd.DataFrame({'x': np.random.randn(200)})

alt.Chart(df).transform_quantile(
    'x', step=0.01
).mark_point().encode(
    x='prob:Q',
    y='value:Q'
)

Transform Options

The transform_quantile() method is built on the QuantileTransform class, which has the following options:

Property

Type

Description

as

array(any)

The output field names for the probability and quantile values.

Default value: ["prob", "value"]

groupby

array(FieldName)

The data fields to group by. If not specified, a single group containing all data objects will be used.

probs

array(number)

An array of probabilities in the range (0, 1) for which to compute quantile values. If not specified, the step parameter will be used.

quantile

FieldName

The data field for which to perform quantile estimation.

step

number

A probability step size (default 0.01) for sampling quantile values. All values from one-half the step size up to 1 (exclusive) will be sampled. This parameter is only used if the probs parameter is not provided.