plot_grouped_scatter_chart()

Plots a grouped or quadrant-mapped scatter plot. Use group_by="category" for color-coded groups, or group_by="quadrant" for a 2×2 strategic matrix.

Quick Example

import pandas as pd
import numpy as np
import clean_charts as cc

np.random.seed(42)
n = 20

df = pd.concat([
    pd.DataFrame({
      "User": [f"P{i}" for i in range(n)], 
      "Time (mins)": np.random.normal(120, 15, n), 
      "Actions": np.random.normal(85, 10, n), 
      "Segment": "Power Users"}),
    pd.DataFrame({
      "User": [f"C{i}" for i in range(n)], 
      "Time (mins)": np.random.normal(30, 10, n), 
      "Actions": np.random.normal(15, 5, n), 
      "Segment": "Casual Browsers"}),
    pd.DataFrame({
      "User": [f"D{i}" for i in range(n)], 
      "Time (mins)": np.random.normal(110, 20, n), 
      "Actions": np.random.normal(20, 8, n), 
      "Segment": "Passive Scrollers"})
])

cc.plot_grouped_scatter_chart(
    data=df,
    title="User Behavior Segments",
    subtitle="Identifying distinct cohorts by in-app activity",
    show_labels=False,
    alpha=1,
    axes_origin=(60,60)
)
Grouped Scatter
Example output for Grouped Scatter.

Data Requirements

  • Categorical mode — 3–4 columns: [Label (opt), X, Y, Category]
  • Quadrant mode — 2–3 columns: [Label (opt), X, Y]

Parameters

Parameter Type Default Scope Description
datapd.DataFrameBuilt-inCommonDataFrame with X, Y, and optional label/category columns.
output_pathstr | NoneNoneCommonFile path to save the chart.
widthint | None700CommonImage width in pixels.
heightint | None500CommonImage height in pixels.
aspect_ratiostr | NoneNoneCommon"square", "landscape", etc.
titlestr | NoneNoneCommonBold header text.
subtitlestr | NoneNoneCommonSecondary text below title.
bg_colorstr | None"#f4f3f0"CommonBackground hex color.
scale_textboolTrueCommonScale fonts proportionally.
group_bystr | NoneNoneUnique"category" or "quadrant".
x_thresholdfloat | NoneMeanUniqueThreshold line for quadrant X division.
y_thresholdfloat | NoneMeanUniqueThreshold line for quadrant Y division.
quadrant_labelslist[str]NoneUniqueLabels for [top-right, top-left, bottom-left, bottom-right].
show_threshold_linesboolTrueUniquePlot the x and y threshold lines.
colorslist[str]AutoUniqueExplicit hex colors for categories/quadrants.
start_colorstr | NoneNoneUniqueGradient start color for groups.
end_colorstr | NoneNoneUniqueGradient end color for groups.
dot_sizefloat80UniqueMarker size (area in points²).
alphafloat0.75UniqueTransparency of points.
x_labelstr | NoneNoneUniqueX-axis label.
y_labelstr | NoneNoneUniqueY-axis label.
show_labelsboolFalseUniqueAnnotate points with labels.