Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

MATLAB Graph Plot: plot, Labels, Subplots and Export

Plot a graph in MATLAB with plot(x,y), then add markers, labels, a legend and subplots and export a publication-ready figure with exportgraphics.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: to plot a graph in MATLAB, pass x and y vectors to plot(x,y). Add a third argument such as "b--o" to set line style, marker and color, label the axes, then save the figure with exportgraphics. This guide goes past the basic call to a complete figure workflow: labels, legend, several plots in one axes, a grid of plots, and export for a manuscript.

What MATLAB plotting is used for in research

Researchers use plot to draw 2-D line graphs of measured or simulated data: time series, calibration curves, model fits, signal traces. A plot is only useful in a paper if it is labelled and exported in a format the publisher accepts, so this page covers those steps as well as the call itself. For the wider role of the software, see what MATLAB is used for.

Open MATLAB

MATLAB is a MathWorks product. Obtain it, or its browser version MATLAB Online, only from MathWorks (mathworks.com) or through your institution’s MathWorks arrangement. Type the commands below in the Command Window or save them in a script file.

How to plot a graph in MATLAB, step by step

The same steps answer the variants “plot graph in MATLAB”, “plot graph MATLAB” and “how to plot graph in MATLAB”.

  1. Create the data. x = 0:pi/10:2*pi; then y = sin(x);
  2. Plot it. plot(x,y) draws y against x. With a single vector, plot(Y) plots against index. Table data uses plot(tbl,xvar,yvar).
  3. Style it. Add a line specification: plot(x,y,"r--o") is a red dashed line with circle markers. Or use name-value pairs: plot([0 1],[2 3],LineWidth=2).
  4. Label it. xlabel("Phase (rad)"), ylabel("Amplitude") and title("Sine wave"). xlabel(txt) labels the x-axis of the current axes.
  5. Add a legend. legend("sin(x)") labels series in order. Place it with legend({"sin(x)"},"Location","southwest").
  6. Export it. exportgraphics(gcf,"sine.pdf",ContentType="vector").

Plot graph in MATLAB with points (markers)

Markers draw a symbol at each data point. Use a marker character in the line specification ("o") or the Marker name-value property. A marker with no line style, such as plot(x,y,"o"), gives a point-only plot. Default marker is none.

Several plots in the same axes

plot(x,y1,"g",x,y2,"b--o",x,y3,"c*") draws three series in one call. To add a series later, use hold on: it retains plots in the current axes so that new plots do not delete existing ones. hold off restores the default, in which a new plot clears the existing one.

A grid of plots: tiledlayout and subplot

subplot(m,n,p) divides the figure into an m-by-n grid and puts the axes at position p. MathWorks describes tiledlayout layouts as more customizable and configurable than those created by subplot, for example through adjustable tile spacing. With tiledlayout(2,2), call nexttile before each plot. Pass the layout object to title, xlabel and ylabel to label the whole layout:

t = tiledlayout(2,2,TileSpacing="compact");
nexttile; plot(x,sin(x))
nexttile; plot(x,cos(x))
title(t,"Trigonometric functions")
xlabel(t,"Phase (rad)")

Reference: line specification characters

Property Values (as documented for plot)
Line style "-" solid (default), "--" dashed, ":" dotted, "-." dash-dotted, "none"
Marker o + * . x _ |, square, diamond, ^ v > <, pentagram, hexagram
Color red r, green g, blue b, cyan c, magenta m, yellow y, black k, white w, or an RGB triplet such as [1 0 0]

For colormaps on surface and image plots, see MATLAB colormap colors.

Worked example: a labelled, exportable figure

x = 0:pi/10:2*pi;
y1 = sin(x); y2 = sin(x-0.25); y3 = sin(x-0.5);
plot(x,y1,"g",x,y2,"b--o",x,y3,"c*")
xlabel("Phase (rad)")
ylabel("Amplitude")
title("Phase-shifted sine waves")
legend("sin(x)","sin(x-0.25)","sin(x-0.5)","Location","southwest")
exportgraphics(gcf,"phase-shift.pdf",ContentType="vector")
exportgraphics(gcf,"phase-shift.png",Resolution=300)

The plot call is MathWorks’ own sine example; the labels, legend and export lines extend it.

Output and how to read it

A figure window opens with the axes drawn to fit the data. Each series is a separate line; the legend maps line style, marker and color to the label you supplied. If you give no label, the legend names series data1, data2 and so on, which is rarely acceptable in a paper. Alternatively set labels while plotting with the DisplayName property, then call legend.

Export for publication

exportgraphics(obj,filename) chooses the format from the file extension. Documented formats: jpg/jpeg, png, tif/tiff, gif, svg (since R2025a), pdf, emf (Windows only), eps, and html (since R2026a).

  • Vector output (ContentType="vector") keeps lines sharp at any size. It is not supported for JPEG, TIFF, PNG, GIF or HTML.
  • Raster output uses Resolution in DPI; the default is 150. exportgraphics(ax,"Peppers300.jpg",Resolution=300) is the vendor’s 300 DPI example. Resolution has no effect on HTML or on "vector" content.

Check your target journal’s artwork instructions for the format and resolution it requires; those rules are the journal’s, not MATLAB’s.

Troubleshooting

  • Only the last plot appears. By default a new plot clears the existing one. Use hold on after the first plot, or plot several series in one plot call.
  • Legend says data1, data2. No label was supplied. Pass labels to legend or set DisplayName.
  • Tick labels overlap between tiles. TileSpacing="none" removes all space between adjacent plot boxes, so tick labels can overlap neighbouring plots. Use "tight", "compact" or the default "loose".
  • Vector export fails or is ignored for PNG or JPEG. Vector content is unsupported for those formats; export PDF or EPS instead.
  • EMF export unavailable. EMF is Windows only.

Free alternatives

Tool Equivalent call Source
GNU Octave plot (x, y, fmt); the fmt string takes linestyle, marker and color, for example "or" for red circles Octave manual, Two-Dimensional Plots
Python Matplotlib import matplotlib.pyplot as plt, then plt.plot(x, y) Matplotlib quick-start guide

For the same task in R, see 3D plots in R. To smooth data before plotting, see MATLAB moving average.

Frequently asked questions

How do I plot a graph in MATLAB?

Define x and y vectors and call plot(x,y). Add xlabel, ylabel and title to label it.

How do I plot a graph in MATLAB with points?

Include a marker in the line specification, for example plot(x,y,"o") for points only or plot(x,y,"-o") for a line with markers.

How do I put several graphs on one plot?

Use one plot call with several x,y pairs, or call hold on before adding more.

How do I add a legend?

Call legend("label 1","label 2") after plotting, in the same order as the series. The default 2-D location is northeast.

Should I use subplot or tiledlayout?

Prefer tiledlayout: MathWorks describes its layouts as more customizable and configurable than subplot layouts, including adjustable tile spacing.

How do I save the graph for a paper?

Use exportgraphics with a vector format such as PDF or EPS, or a raster format with Resolution=300.

Sources

Checked 2026-11-07.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about MATLAB Graph Plot: plot, Labels, Subplots and Export

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →