Scope
This is an extensive digest of the Seaborn Visualizing Distributions of Data through both axes-level functions and figure-level functions. These can help answer whether data is skewed, range of observations, known tendencies or directionality, bimodal behavior, outliers, and hidden patterns learned through exploratory data analysis or EDA.
**Prerequisite Environment Setup**
To get started on Jupyter Notebook or Google Colab, use !pip install seaborn if module is not found in dependencies. Use import seaborn as sns for namespace, then use sns.load_dataset([“DATA”]) to load from a url.
Step-by-Step Execution Workflow
(The displot() function is ideal for representing continuous, numerical data and assuming its positive-only. Start with sns.displot(data, x=”column”), and use the binwidth parameter to set bin sizes for custom control of how data structure is presented. Use sns.displot(data, x=”column”, binwidth=2) if smaller bin width is required for visualizing variant data.
Seaborn allows for custom bin counts by passing an array to bins. Use sns.displot(data, x=”size”, bins=[1, 2, 3, 4, 5, 6, 7]) so create seven stacked columns, which better quarters sets where data may be heavily skewed. Distribution plots also can be additionally modified via discrete=True, which breaks bins that have unique values over bins that are centered on their connecting values. Discrete bins are also suitable for categorical variables, but if needed, shrink can be used to strengthen the relation of the axis’ categorical component. When featuring visualization parameters, bimodal features are important to distinguish between groups via color.
The hue argument is good for assigning unique values based on a group, which must be at least two or more. The code sns.displot(data, x=” column”, hue=” species”)
Different and distinct histograms are layered or caked, so overlap is expected, which is why the alternating to a “step” plot is smarter so that plots are layered appropriately. This is truer with modality far higher than two and when variance is high. Stacked histograms can be replicated by using the keyword “stack”, which stacks bars vertically without overlap. Use sns.displot(data, x=” column”, hue=”hue group”, multiple=” stack”)
When determining the mode or mean, the stack option may not be suitable, so using another option called dodge, which separates columns for width reduction, to prevent overlap.
However, using a dodge feature is only suitable for strictly bimodal or two groups.
Because displot() creates a Facet Grid object, its figure-level and means that individual customization into disparate subplots through assigning of a second variable to col or row. Expressed as sns.displot(data, x=”column_1”, col=”column_2”), modified instances of col and row are best using discrete data, such as sex, true/false, weekdays, time, binary, or other discrete and easily categorical information. When magnitudes become apparent in data where unequal weights are present, using normalization from the stat parameter is important: use sns.displot(data, x=”column_1”, hue=”column_2”, stat=”density”).
Top comments (0)