plot_scatter_chart()

Plots a 2D scatter plot in the Economist style. Best for visualizing relationships, correlations, and distributions between two continuous variables.

Quick Example

import pandas as pd
import clean_charts as cc

df = pd.DataFrame({
    "Company": ["AAPL", "MSFT", "GOOG", "AMZN", "META", "TSLA", "NVDA", "JPM"],
    "Revenue Growth (%)": [8, 12, 15, 11, 22, 19, 45, 6],
    "Profit Margin (%)": [26, 37, 25, 6, 28, 12, 55, 33]
})

cc.plot_scatter_chart(
    data=df,
    title="Tech Giants Performance",
    subtitle="Revenue Growth vs Profit Margin",
    x_label="Revenue Growth",
    y_label="Profit Margin",
    x_suffix="%",
    y_suffix="%",
    show_labels=True
)
Scatter
Example output for Scatter.

Data Requirements

  • 2 columns — [X values, Y values]
  • 3 columns — [Labels, X values, Y values] (labels used when show_labels=True)

Parameters

Parameter Type Default Scope Description
datapd.DataFrameBuilt-inCommon2 or 3-column DataFrame.
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.
colorstr | NoneAutoUniqueHex color for scatter dots.
dot_sizefloat80UniqueMarker size (area in points²).
alphafloat0.75UniqueTransparency of scatter points (0.0–1.0).
x_labelstr | NoneNoneUniqueX-axis label text.
y_labelstr | NoneNoneUniqueY-axis label text.
x_suffixstr""UniqueSuffix for X-axis annotations.
y_suffixstr""UniqueSuffix for Y-axis annotations.
show_labelsboolFalseUniqueAnnotate points with label strings.
show_trendlineboolFalseUniquePlot a linear regression trend line.
trendline_colorstr | NoneNoneUniqueHex color for the trend line.

Common Scenarios

Labeled Scatter with Trend

df = pd.DataFrame({
    "Company": ["AAPL", "MSFT", "GOOG", "AMZN", "META", "TSLA", "NVDA", "JPM"],
    "Revenue Growth (%)": [8, 12, 15, 11, 22, 19, 45, 6],
    "Profit Margin (%)": [26, 37, 25, 6, 28, 12, 55, 33]
})

cc.plot_scatter_chart(
    data=df,
    title="Growth vs Profitability",
    show_labels=True,
    show_trendline=True,
    trendline_color="#635bff"
)
Scatter
Example output for Scatter.