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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Pass a marker argument to each Axes.scatter call when plots need different shapes. To give plots a shared default, set Matplotlib’s scatter.marker rcParam, optionally inside a temporary rc_context. Use s to size scatter points; it does not use the same convention as plot’s markersize.

Set a different marker for each scatter plot

Give each axes its own marker value. In this two-panel example, the first scatter plot uses circles and the second uses upward-pointing triangles:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(x1, y1, marker="o", s=36, label="Group A")
ax2.scatter(x2, y2, marker="^", s=36, label="Group B")

Replace x1, y1, x2, and y2 with your data. The marker argument accepts a marker shorthand or a MarkerStyle instance, as described in the Axes.scatter API. Common shorthands include "o" for a circle, "s" for a square, "^" for an upward triangle, "D" for a diamond, and "*" for a star. See the plot API marker examples for additional shorthand examples.

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

Apply one default to several plots

Set scatter.marker when plots should use the same marker unless an individual call specifies otherwise. For a temporary setting limited to a block of code, use matplotlib.rc_context:

import matplotlib as mpl
import matplotlib.pyplot as plt

with mpl.rc_context({"scatter.marker": "s"}):
    fig, (ax1, ax2) = plt.subplots(1, 2)
    ax1.scatter(x1, y1)
    ax2.scatter(x2, y2)

Both scatter calls use squares by default within the block. A call-level marker argument lets a particular plot use a different shape. When the block ends, the temporary configuration no longer applies. Matplotlib also supports style sheets and matplotlibrc for reusable settings; its documented configuration precedence is runtime rc settings, then style sheets, then matplotlibrc. See the configuration and rcParams guide and customization guide.

Choose between per-plot and shared styling

Method Scope Use it when
marker=... in scatter One scatter call Plots need different shapes, or one plot should differ from a shared default.
scatter.marker in rc_context One code block Several plots should share a temporary default without changing configuration outside the block.
Style sheet or matplotlibrc Reusable configuration You want a marker default available beyond a single block; runtime rc settings and style sheets take precedence over matplotlibrc.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Size scatter markers with the right parameter

In scatter, s specifies marker size approximately in proportion to visual area. In plot, markersize is measured in points and generally corresponds to marker width or diameter. The values are therefore not interchangeable: copying a number from plot(markersize=...) into scatter(s=...) does not preserve the same apparent dimensions. The distinction is covered in Matplotlib’s quick start guide.

s can be a scalar for a consistent size or array-like for point-by-point sizes. Scatter plots also support face color, edge color, transparency, and color mapping. For an example of varying size and color, see Matplotlib’s scatter plot example. Use shapes and colors consistently, and label groups when readers need help identifying what each encoding represents.

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

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.