October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Make a Matplotlib Scatter Plot and Fit Its Labels

Plot paired data with Matplotlib scatter, adjust label spacing with tight_layout(), and learn when constrained layout handles legends and colorbars better.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use ax.scatter(x, y) to plot paired values, then call fig.tight_layout() after adding the title and axis labels for a simple, one-time spacing adjustment. For plots with legends, colorbars, or more complex layouts, create the figure with layout="constrained" instead; do not call tight_layout() afterward.

Make a scatter plot and adjust its layout

This example plots five paired observations, adds labels and a title, then asks Matplotlib to adjust subplot spacing:

As an Amazon Associate I earn from qualifying purchases.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 1, 4, 3, 5]

fig, ax = plt.subplots()
ax.scatter(x, y, s=40, color="tab:blue", alpha=0.8)
ax.set_xlabel("X value")
ax.set_ylabel("Y value")
ax.set_title("Example scatter plot")
fig.tight_layout()
plt.show()

x and y give the horizontal and vertical positions of the points. The s argument sets marker area in typographic points squared, not its radius. color assigns one color to all points, and alpha controls transparency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call fig.tight_layout() after adding plot decorations so Matplotlib can adjust spacing around the Axes. It adjusts the figure when called; it does not normally recalculate layout on every redraw. The official Matplotlib tight layout guide describes automatic behavior as something you can enable separately with fig.set_tight_layout(True) or the figure.autolayout setting.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Encode another variable with marker color or size

Map numeric values to color

To show a third numeric variable, pass its values as c. A colormap maps those values to colors; use cmap to select the map and norm when you need control over how values are normalized:

fig, ax = plt.subplots()
points = ax.scatter(x, y, c=[10, 20, 30, 40, 50], cmap="viridis")
ax.set_xlabel("X value")
ax.set_ylabel("Y value")
ax.set_title("Scatter plot colored by a third variable")
fig.colorbar(points, ax=ax, label="Third variable")
fig.tight_layout()

The colorbar explains how the numeric values correspond to color. Because colorbars add layout complexity, constrained layout is often a better choice for this version.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Vary marker size

Supply a sequence to s to vary marker area for each point. Since the values are in points squared, choose them as areas rather than treating them as radii. The Matplotlib scatter API documents the available marker, size, color, transparency, edge, and colormap options.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an unambiguous color argument

Use color="tab:blue" for a uniform color. The c argument can mean a color specification, per-point colors, numeric values for colormapping, or an RGB(A) array, so a single numeric RGB(A) sequence can be ambiguous with data values. The scatter API recommends color= when all points should share one color.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Marker edges can also change how large points appear: edge linewidth is centered on the marker boundary, so a positive linewidth can make small markers look larger. To remove edges, use linewidths=0 or edgecolors="none".

Choose between tight layout and constrained layout

Layout choice How to activate it What it handles Best fit
tight_layout Call fig.tight_layout() after adding plot elements. Primarily tick labels, axis labels, and titles. Simple figures needing a one-time spacing adjustment.
Constrained layout Create the figure with fig, ax = plt.subplots(layout="constrained"). Labels and titles, plus elements such as legends and colorbars; supports more complex grids. Figures with multiple Axes or more involved arrangements.

Matplotlib’s constrained layout guide recommends enabling it when creating the figure, before adding Axes. For example:

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
fig, ax = plt.subplots(layout="constrained")
ax.scatter(x, y)
ax.set_xlabel("X value")
ax.set_ylabel("Y value")
ax.set_title("Example scatter plot")
plt.show()

Do not follow this with fig.tight_layout(): calling tight layout turns constrained layout off. Matplotlib’s tight layout guide says the more modern and capable constrained layout should typically be used instead.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the rendered figure when text is still cut off

tight_layout is not a guarantee against clipping. Its documented extent checks focus on tick labels, axis labels, and titles, and the guide notes that it may not work in every case. Some artists can be excluded from layout calculations with Artist.set_in_layout, which may affect the available spacing.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
  • Inspect the displayed figure or the saved output; layout results can depend on the figure’s decorations and geometry.
  • Avoid setting pad=0 if text is close to the edge. The guide warns that zero padding can clip text by a few pixels and recommends padding greater than 0.3.
  • If you call tight layout repeatedly, small variations are possible because the algorithm does not necessarily converge.
  • For a crowded plot with a legend, colorbar, or multiple Axes, try constrained layout from figure creation instead of relying on a later tight-layout adjustment.

For extra separation with the simpler layout, fig.tight_layout(pad=1.2) increases padding; w_pad and h_pad control horizontal and vertical spacing. These padding values are fractions of the font size, as documented in the tight layout guide. Check the actual output after changing them.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.