Menu

Scatter Plots and Bubble Charts

Scatter Plots and Bubble Charts

Scatter plots show how two numeric values relate to each other. Adding size and color lets you show even more. This topic covers how to build them and read the patterns they reveal.

a. Creating Scatter Plots

A scatter plot places a dot for each item, using one value for the horizontal position and another for the vertical position. It is the standard chart for studying the relationship between two numeric columns.

fig, ax = plt.subplots()
ax.scatter(df["ad_spend"], df["sales"])
ax.set_xlabel("Ad Spend")
ax.set_ylabel("Sales")
ax.set_title("Ad Spend vs Sales")
plt.show()

Each dot is one record, such as one store or one month. The overall shape of the dots tells the story. You can see trends, clusters, and unusual points at once.

If you have many dots that overlap, make them partly see-through with the alpha setting. This helps you see where the data is dense.

b. Spotting Patterns and Correlation

When dots rise from the lower left to the upper right, the two values have a positive relationship. When dots fall from the upper left to the lower right, the relationship is negative. When dots form a cloud with no direction, there is little or no relationship.

You can add a trend line to make the pattern clearer. NumPy can fit a simple line through the points.

import numpy as np
m, b = np.polyfit(df["ad_spend"], df["sales"], 1)
ax.plot(df["ad_spend"], m * df["ad_spend"] + b, color="red")

Remember that correlation does not mean cause. Two things can move together without one causing the other. Use the chart as a hint and not as proof.

c. Adding a Third Variable with Bubble Charts

A bubble chart is a scatter plot where the size of each dot shows a third value. For example, you can plot ad spend against sales, and let the bubble size show the number of customers.

ax.scatter(df["ad_spend"], df["sales"],
s=df["customers"] * 2, alpha=0.5)

The s setting controls the size. Scale the values so that the bubbles are neither too tiny nor too large. Use transparency so overlapping bubbles stay visible.

You can also use color to show a category or a fourth variable. Do not add too much, since the chart can quickly become hard to read.

d. Adding Titles, Labels, and Legends

A chart is only useful when people can understand it. Add a clear title that says what the chart shows. Label both axes and include units, such as "Sales (in thousands)".

If you use color or size for extra information, add a legend to explain them. Place it where it does not hide the data.

ax.set_title("Ad Spend vs Sales by Region")
ax.legend(title="Region")
ax.grid(True, alpha=0.3)

A light grid helps readers estimate values. Keep the design simple and clean. Every element on the chart should help the viewer understand the message.


Data Visualization Tutorial

WR

Wesline Rinisha



Learn via Video Course

Data Visualization Using Python Logo

Data Visualization Using Python

19 hrs



Get in Touch For Details