Line Plots, Scatter, and Error Bars

The Workhorse Plots of Engineering

Line plots and scatter plots are the bread and butter of scientific visualization. BER curves, convergence plots, measurement series, and parameter sweeps all rely on line/scatter plots with error bars and confidence intervals. Mastering ax.plot(), ax.scatter(), ax.errorbar(), and ax.fill_between() covers 80% of your daily plotting needs.

Definition:

Line Plot (ax.plot)

ax.plot(x, y, fmt, **kwargs) draws connected line segments between (xi,yi)(x_i, y_i) pairs. The format string fmt combines color, marker, and linestyle:

ax.plot(x, y, 'r--o')  # red dashed line with circle markers
ax.plot(x, y, color='#2563EB', linewidth=2, marker='s',
        markersize=6, markerfacecolor='white', label='BPSK')

Key keyword arguments: linewidth (lw), linestyle (ls), marker, markersize (ms), markeredgecolor (mec), markerfacecolor (mfc), alpha, label, zorder.

Multiple ax.plot() calls on the same Axes overlay the curves. Use label and ax.legend() to distinguish them.

Definition:

Scatter Plot (ax.scatter)

ax.scatter(x, y, s, c, **kwargs) places markers at (xi,yi)(x_i, y_i) with per-point size s and color c:

ax.scatter(snr_db, throughput, s=errors*10,
           c=ber, cmap='viridis', norm=LogNorm())

Unlike ax.plot(), scatter supports array-valued sizes and colors, making it ideal for visualizing three or four dimensions simultaneously.

Use ax.plot() when all markers share the same size and color. Use ax.scatter() when marker properties vary per point.

Theorem: Confidence Interval Width Scaling

For NN independent measurements of a quantity with standard deviation Οƒ\sigma, the 95% confidence interval for the mean has half-width:

Ξ”=1.96β‹…ΟƒN\Delta = 1.96 \cdot \frac{\sigma}{\sqrt{N}}

Halving the CI width requires 4Γ—4\times the measurements. For BER estimation with error count kk in NN trials:

P^b=kN,ΟƒP^β‰ˆP^b(1βˆ’P^b)N\hat{P}_b = \frac{k}{N}, \quad \sigma_{\hat{P}} \approx \sqrt{\frac{\hat{P}_b(1-\hat{P}_b)}{N}}

This 1/N1/\sqrt{N} scaling is why BER curves require millions of bits at high SNR. Always show error bars to communicate measurement uncertainty.

Example: BER Curve with Confidence Intervals

Plot a BER curve for BPSK with simulated error bars and a theoretical reference on a semilogy scale.

Example: Confidence Bands with fill_between

Show a shaded 95% confidence band around an estimated channel capacity curve.

Example: Overlaying Multiple Modulation BER Curves

Plot BER curves for BPSK, QPSK, and 16-QAM on the same axes with distinct markers and a legend.

BER Curve Explorer

Explore BER curves for different modulation schemes with adjustable SNR range and optional error bars.

Parameters

Scatter Plot with Colormap

Visualize throughput vs. distance with color-coded BER and size-coded number of users.

Parameters

Common Mistake: Plotting Zero on a Log Scale

Mistake:

BER values of exactly 0 cause semilogy to silently drop those points (log(0) is undefined).

Correction:

Replace zeros with a small value or mask them:

ber_plot = np.where(ber > 0, ber, np.nan)
ax.semilogy(snr_db, ber_plot, 'o-')

Key Takeaway

Always plot error bars or confidence bands on simulation results. A BER or throughput curve without uncertainty information is scientifically incomplete. Use ax.errorbar() for discrete points and ax.fill_between() for continuous bands.

Quick Check

When should you use ax.scatter() instead of ax.plot()?

When you need a log scale

When each point needs a different size or color

When plotting more than 1000 points

When you want connected lines

Error Bar

A graphical indicator of uncertainty, typically showing the confidence interval or standard error around each data point.

Related: Confidence Interval (CI)

Confidence Interval (CI)

A range of values that contains the true parameter with a specified probability (e.g., 95%).