Categorical Plots

Existing Python plotting libraries such as seaborn nad plotly have excellent support for high-level categorical plotting methods that use DataFrame objects as input.

In whitecanvas, we provide similar functionality, but these methods does not depend on any external plotting libraries or DataFrames.

The cat namespace

The cat namespace converts a tabular data into a categorical plotter. Currently, following objects are allowed as input:

  • dict of array-like objects

  • pandas.DataFrame

  • polars.DataFrame

from whitecanvas import new_canvas

canvas = new_canvas("matplotlib")

# sample data
df = {
    "label": ["A"] * 60 + ["B"] * 30 + ["C"] * 40,
    "value": np.random.normal(size=130),
}

canvas.cat(df, by="label").add_stripplot("value")
canvas.show()

You can directly pass a categorized dict object. In this case, you should not specify the column name parameters.

from whitecanvas import new_canvas

canvas = new_canvas("matplotlib")

# sample data
df = {
    "A": np.random.normal(size=60),
    "B": np.random.normal(size=30),
    "C": np.random.normal(size=40),
}

canvas.cat(df).add_stripplot()
canvas.show()

Several plotting methods are available in the cat namespace:

  • add_stripplot()

  • add_boxplot()

  • add_violinplot()

  • add_swarmplot()

  • add_countplot()