Color-Mapped Scatter Plot — plotnine

A scatter plot that encodes a third continuous variable using a colormap, allowing visualization of three dimensions on a 2D plane. This visualization is essential for exploring multivariate relationships where the third variable represents intensity, magnitude, or any continuous measurement. A colorbar provides a reference scale for interpreting the color values.

Color-Mapped Scatter Plot rendered with plotnine

Renders

Python source (plotnine)

""" anyplot.ai
scatter-color-mapped: Color-Mapped Scatter Plot
Library: plotnine 0.15.4 | Python 3.13.13
Quality: 85/100 | Updated: 2026-05-08
"""

import numpy as np
import pandas as pd
from plotnine import aes, element_text, geom_point, ggplot, labs, scale_color_cmap, theme, theme_minimal


# Data - Temperature readings across a sensor grid
np.random.seed(42)
n = 150

# Sensor positions and temperature measurements
x = np.random.uniform(0, 100, n)
y = np.random.uniform(0, 100, n)
# Temperature with spatial pattern - warmer in upper right
temperature = 20 + 0.15 * x + 0.1 * y + np.random.normal(0, 3, n)

df = pd.DataFrame({"x_position": x, "y_position": y, "temperature": temperature})

# Create plot
plot = (
    ggplot(df, aes(x="x_position", y="y_position", color="temperature"))
    + geom_point(size=4, alpha=0.8)
    + scale_color_cmap(cmap_name="viridis")
    + labs(
        x="X Position (m)",
        y="Y Position (m)",
        color="Temperature (°C)",
        title="scatter-color-mapped · plotnine · pyplots.ai",
    )
    + theme_minimal()
    + theme(
        figure_size=(16, 9),
        text=element_text(size=14),
        axis_title=element_text(size=20),
        axis_text=element_text(size=16),
        plot_title=element_text(size=24),
        legend_text=element_text(size=14),
        legend_title=element_text(size=16),
    )
)

# Save
plot.save("plot.png", dpi=300)

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/scatter-color-mapped/plotnine/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "scatter-color-mapped",
  "language": "python",
  "library": "plotnine",
  "page": "https://anyplot.ai/scatter-color-mapped/python/plotnine",
  "hub": "https://anyplot.ai/scatter-color-mapped",
  "code_json": "https://api.anyplot.ai/specs/scatter-color-mapped/plotnine/code",
  "spec_json": "https://api.anyplot.ai/specs/scatter-color-mapped",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/scatter-color-mapped/python/plotnine/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/scatter-color-mapped/python/plotnine/plot-dark.png",
  "quality_score": 85.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Color-Mapped Scatter Plot on anyplot.ai.

Other implementations