Start with the question you want the figure to answer. Use a line plot to show how a value changes, scatter to compare individual observations, a histogram to inspect a distribution, and image, contour, or surface plots to explore values across a grid. The MATLAB Plot Gallery shows these representations side by side and opens every example in the browser sandbox.
Every comparison on this page is rendered in RunMat. You can run the same MATLAB-compatible plotting code in the browser sandbox, or open a local .m file in RunMat Desktop and use your own data. The runnable comparison near the end opens the four-panel example in the browser workspace so you can change the samples and run it again.

The number of array dimensions does not settle the choice. A matrix might contain image intensities, labeled measurements, temperatures over a grid, or surface heights. The plot should preserve the structure that matters to the analysis.
MATLAB plot types by data structure
Start with the data or question in the first column. Each function link opens the RunMat builtin reference with current call forms and examples.
| Data or analytical task | Start with | Basic syntax |
|---|---|---|
| Ordered samples over time or another continuous domain | plot | plot(x, y) |
| Independent observations | scatter | scatter(x, y) |
| Values that persist until the next sample | stairs | stairs(x, y) |
| A discrete sequence tied to a baseline | stem | stem(x, y) |
| Measurements with uncertainty or tolerances | errorbar | errorbar(x, y, err) |
| Cumulative magnitude over an ordered domain | area | area(x, y) |
| Category totals or grouped comparisons | bar | bar(x, Y) |
| The distribution of one sample set | histogram | histogram(samples) |
| Quartiles, spread, and outliers | boxplot | boxplot(samples) |
| Dense paired observations summarized into tiles | binscatter | binscatter(x, y) |
| Joint counts over two numeric variables | histogram2 | histogram2(x, y) |
| Cell-wise spatial variation in a matrix | imagesc or image | imagesc(Z) |
| A labeled matrix or table-like comparison | heatmap | heatmap(Z) |
| Equal-value lines or filled regions in a sampled field | contour or contourf | contourf(X, Y, Z) |
| Equal-value lines from a function of two variables | fcontour | fcontour(fun) |
| Height and shape over a sampled grid | surf or mesh | surf(X, Y, Z) |
| A surface from a function of two variables | fsurf | fsurf(fun) |
| Direction and magnitude over a 2-D domain | quiver | quiver(X, Y, U, V) |
| Direction and magnitude in three dimensions | quiver3 | quiver3(X, Y, Z, U, V, W) |
| A connected path in three dimensions | plot3 | plot3(x, y, z) |
| Independent observations in three dimensions | scatter3 | scatter3(x, y, z) |
| Scalar level curves at their 3-D heights | contour3 | contour3(X, Y, Z) |
| One or both axes span several orders of magnitude | semilogx, semilogy, or loglog | loglog(x, y) |
| A connected angular response | polarplot | polarplot(theta, rho) |
| Independent angular observations | polarscatter | polarscatter(theta, rho) |
| The distribution of angles | polarhistogram | polarhistogram(theta) |
Several functions can display the same numeric values. The differences below concern what those displays ask the reader to perceive.
Plot vs scatter, stairs, and stem
Use plot when neighboring samples form an ordered path. Time series, sampled responses, and trajectories fit this representation because the connecting segments make adjacency visible.
Use scatter when each observation should stand alone. Correlation studies, experimental point sets, and measurement clouds usually do not gain meaning from row order.
Use stairs when one sample remains in effect until the next boundary. Controller states, digital values, and piecewise-constant commands should show the interval over which each value persists.
Use stem when the samples are discrete and their distance from a baseline belongs to the interpretation. Discrete-time sequences and impulse-like data commonly use this form.

errorbar extends an ordered or point-based view when the uncertainty interval is part of the result. area shifts attention from the line itself to accumulated magnitude or contributions over the domain.
Bar vs histogram, boxplot, and binned scatter
A bar chart compares values that have already been assigned to categories or groups. The horizontal positions name discrete cases such as components, test conditions, or product groups.
A histogram groups numeric samples into adjacent intervals. Its bars show how often measurements fall into each range. Changing the bin edges changes the summary, so the binning belongs to the analysis.
A boxplot compresses a distribution into its median, quartiles, whiskers, and outliers. It works well when several groups must be compared in limited space. A histogram reveals more of the distribution's shape; a box plot makes location and spread easier to compare across groups.
Dense paired observations need a two-variable summary. binscatter colors rectangular tiles by observation density. histogram2 counts observations in a two-dimensional bin grid and presents the joint distribution as binned geometry. An ordinary scatter plot remains useful when individual points are still legible.

Individual observations preserve point-level detail, the binned image exposes joint density, and the two histograms show each variable's marginal distribution.
Use pie only when a small number of values form a meaningful whole and broad proportions are the message. A bar chart supports more precise magnitude comparison.
Imagesc vs heatmap, contour, surf, and mesh
image and imagesc map matrix cells to a raster-like view. imagesc scales the values across the active colormap, which makes dense spatial variation easy to inspect. Color communicates value; the display does not print exact cell values by itself.
heatmap treats the matrix as a labeled chart. It is a better fit when row and column categories matter more than continuous image coordinates.
contour extracts equal-value lines from a sampled scalar field. contourf fills the regions between levels. These views make thresholds, bands, ridges, and boundaries easier to compare without perspective.
fcontour applies the same level-set idea to a function of two variables. Use it when the source is a function handle rather than a precomputed Z matrix.
surf maps scalar value to height and filled color. It exposes shape, slope, and curvature. mesh keeps the sampled lattice visible as a wireframe. surfc and meshc add a contour projection below the surface.
fsurf samples a function of two variables and renders the result as a surface. It removes the separate grid-construction step when the function form is the input you want to preserve.

The same sampled field can emphasize cell-wise variation, equal-value regions, continuous shape, or the underlying grid.
A 2-D field view usually supports regional comparison better than a perspective view. Use height when the geometry itself is part of the result.
Quiver vs quiver3 and other 3-D plots
quiver shows a vector at each location in a two-dimensional domain. Arrow orientation carries direction and arrow length carries magnitude. A contour or image layer can add scalar context such as speed or field strength.
quiver3 extends the same representation to positions and vectors with three coordinates. Use it when the out-of-plane component matters to the field rather than merely adding visual depth.
For coordinate data, plot3 connects an ordered trajectory and scatter3 preserves independent points. contour3 places level curves at their scalar heights. Surface functions describe a gridded field, while these three functions describe paths, point sets, or level geometry.
Perspective can hide points and change apparent distances. A 3-D view earns its place when the third coordinate changes the interpretation.
Linear, logarithmic, and polar coordinates
Changing the axes can reveal structure without changing the underlying data.
Use semilogx when the independent variable spans orders of magnitude, semilogy when the response does, and loglog when both axes need logarithmic scaling. These functions create the plot with the requested scale. xscale and yscale change an existing axes, which is useful when several plot objects already share it.
plot(x, y);
xscale('log');
yscale('log');Logarithmic axes require positive values on the scaled dimensions and express equal ratios as equal distances. Linear axes preserve equal differences.
Use polarplot for a connected response over angle, polarscatter for independent angular observations, and polarhistogram for an angular distribution. Polar coordinates are most direct when angle is the natural domain, as in directional response, phase, and orientation measurements.
Common MATLAB plot comparisons
| Decision | Prefer the first option when | Prefer the second option when |
|---|---|---|
plot vs scatter | Neighboring values form an ordered path | Observations should remain independent |
bar vs histogram | Values belong to named categories | Numeric samples must be binned into ranges |
histogram vs boxplot | Distribution shape and modes matter | Several groups need compact comparison |
scatter vs binscatter | Individual observations remain readable | Overplotting hides local density |
binscatter vs histogram2 | A flat density map supports comparison | Binned joint counts should read as geometry |
imagesc vs heatmap | Matrix position and dense variation are primary | Labels and table-like comparison are primary |
contourf vs surf | Regions and thresholds should be easy to compare | Height and geometric shape are the result |
surf vs mesh | Filled faces make shape easier to read | The sampled grid should remain visible |
quiver vs quiver3 | The field belongs to a plane | Out-of-plane position and direction matter |
plot3 vs scatter3 | Points form a connected trajectory | Points form an independent cloud |
polarplot vs polarscatter | Angular samples form an ordered response | Angular observations should remain independent |
Reference lines such as xline and yline annotate a chosen representation. Add them for thresholds, event times, limits, or targets after selecting the primary plot.
Run the ordered-samples comparison
This example holds the data constant and changes only the representation. Run it as written, then replace the values with your own samples and decide which relationship should remain visible.
x = 0:8;
y = [1 2 2 4 3 5 5 4 6];
subplot(2, 2, 1);
plot(x, y, 'o-');
title('Connected trend');
grid on;
subplot(2, 2, 2);
scatter(x, y, 45, y, 'filled');
title('Independent observations');
grid on;
subplot(2, 2, 3);
stairs(x, y);
title('Persistent value');
grid on;
subplot(2, 2, 4);
stem(x, y);
title('Discrete sequence');
grid on;Frequently asked questions
What is the best MATLAB plot type for time-series data?⌄
Start with plot when the samples occur in time order and connecting them communicates the trend. Use stairs for piecewise-constant states and semilogy when the response spans several orders of magnitude.
When should I use plot instead of scatter?⌄
Use plot when adjacent samples form a meaningful path, such as a time series or sampled response. Use scatter when observations remain independent or marker size and color carry additional variables.
What is the difference between a bar chart and a histogram?⌄
bar compares categories or groups. histogram groups numeric samples into adjacent intervals to show a distribution. Bar positions identify categories; histogram bins represent numeric ranges.
When should I use a histogram instead of a boxplot?⌄
Use a histogram when the distribution's shape, modes, or gaps matter. Use a box plot when medians, quartiles, spread, and outliers must be compared across several groups.
How should I visualize a matrix?⌄
Use imagesc when matrix position and dense cell-wise variation are primary. Use heatmap for labeled rows and columns, contourf for value regions, and surf when values should become height.
When should I use contourf instead of surf?⌄
Use contourf when the reader needs to compare bands, thresholds, or regions without perspective. Use surf when slope, curvature, and three-dimensional shape belong to the result.
When should a plot use logarithmic axes?⌄
Use semilogx, semilogy, loglog, or axes scale commands when meaningful variation is compressed because one or both dimensions span several orders of magnitude. Keep linear axes when equal differences in the original units should remain equal distances.
Related plotting documentation
- Browse the MATLAB Plot Gallery for rendered examples and code that opens directly in the browser sandbox.
- How to plot and style MATLAB figures covers functions, multiple series, subplots, 3-D figures, animation, and image export.
- Plotting in RunMat explains figure state and the rendering workflow.
- Figure state and graphics handles covers figures, axes, legends,
get, andset. - Plot replay and export distinguishes editable scene state from fixed image output.
- Builtin function reference lists the current documented functions and call forms.