October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober 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 Create a Scatter Plot in Pandas

Use pandas DataFrame.plot.scatter() to compare two numeric columns, then format axes or encode a third variable with marker color or size.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use DataFrame.plot.scatter() to plot one pandas column against another: set x to the horizontal column and y to the vertical column. For example, df.plot.scatter(x="height", y="weight") creates a scatter plot from those two numeric columns and returns Matplotlib axes you can format.

Create a scatter plot from two columns

Each row in the DataFrame represents an observation; its values in the selected columns determine that point’s horizontal and vertical coordinates. The pandas visualization guide specifies numeric columns for both axes. Use the exact column labels, or integer column positions, in the call.

ax = df.plot.scatter(x="hours_studied", y="exam_score")

The API reference documents DataFrame.plot.scatter in pandas 3.0.5, and the visualization guide retrieved for this article is labeled pandas 3.0.6. These are documentation versions, not a claim about the version installed in your environment. See the pandas scatter plot API and pandas chart visualization guide.

Format the plot

The method returns a Matplotlib Axes object, which you can keep in a variable and use to set labels and a title. Pandas plotting also forwards supported keyword arguments to Matplotlib.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ax = df.plot.scatter(x="hours_studied", y="exam_score")
ax.set_title("Study time and exam score")
ax.set_xlabel("Hours studied")
ax.set_ylabel("Exam score")

For a complete display example, import Matplotlib’s pyplot module and call show(). Add tight_layout() if you want Matplotlib to adjust spacing around the labels.

import matplotlib.pyplot as plt

ax = df.plot.scatter(
    x="height",
    y="weight",
    s=40,
    alpha=0.6,
    title="Height and weight",
)
ax.set_xlabel("Height (cm)")
ax.set_ylabel("Weight (kg)")
plt.tight_layout()
plt.show()

This is an API example; its values illustrate options rather than prescribe a universally suitable marker size or transparency.

Use color or size to show a third variable

Marker size and color can encode additional data. The scatter API documents s as accepting a scalar, array-like values, or a column name. The c argument accepts a color, color sequence, or a column whose values are mapped through a colormap.

  • s=40 gives points a uniform size; use a size column or array when marker area should reflect a meaningful measure.
  • c="group_code" maps the values in that column to colors; add a colormap such as colormap="viridis" to specify the scale.
  • When color represents data, explain what the colors mean and include a colorbar or other clear key where it helps readers interpret the plot.
ax = df.plot.scatter(
    x="height",
    y="weight",
    c="group_code",
    colormap="viridis",
)

Transparency, set with alpha, can help reveal overlapping points. Matplotlib’s gallery demonstrates alpha=0.5 and marker areas passed through s; the appropriate settings depend on the data and chart. See the Matplotlib scatter plot example.

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

Check missing values and point overlap

Missing values

The pandas visualization guide says scatter plots drop missing values. A plot may therefore contain fewer points than the DataFrame has rows. Check missing values in the selected columns and decide whether omitting those observations affects how you interpret the relationship.

Dense point clouds

If many points overlap, individual observations can become difficult to distinguish. Consider DataFrame.plot.hexbin, which the pandas guide identifies as useful when data are too dense to plot point by point. Compare whether it communicates the density more clearly than the scatter plot for your question.

Rank #4
Sale
Pandas Journal (Diary, Notebook)
  • Crisp writing pages are perfect for personal reflections, sketching, or for recording favorite quotations or poems.
  • Premium 120 gsm paper takes pen or pencil beautifully.
  • Paper is acid free and of archival quality.
  • Light gray lines subtly guide your writing.
  • An inside back cover pocket expands to hold notes, cards, mementos, and more.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When you need to compare many columns

A single scatter plot is suited to a focused comparison between two variables. If you want to inspect pairwise relationships across several numeric columns, pandas.plotting.scatter_matrix creates a grid of pairwise scatter plots and places histograms or KDE plots along the diagonal. Use the single plot when you need to focus on one relationship; use the matrix when broader pairwise exploration is the goal. The pandas visualization guide describes hexbin plots and scatter matrices.

Quick Recap

SaleBestseller No. 4
Pandas Journal (Diary, Notebook)
Pandas Journal (Diary, Notebook)
Premium 120 gsm paper takes pen or pencil beautifully.; Paper is acid free and of archival quality.
$10.99
Bestseller No. 5
Pandas Funny GIS/Programming/Python T-Shirt, Men, Black, Small
Pandas Funny GIS/Programming/Python T-Shirt, Men, Black, Small
Funny design. Import pandas as pd, an all too familiar python code.; Lightweight, Classic fit, Double-needle sleeve and bottom hem
$19.99
Best Value
Pandas Funny GIS/Programming/Python T-Shirt, Men, Black, Small
  • Funny design. Import pandas as pd, an all too familiar python code.
  • Featuring a familiar python code, this will get a laugh from all the nearby programmers and GIS professionals.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

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.

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

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
PC Slower Than It Used to Be?Free scan - under a minute
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.