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 Plot Color: Line Color, Hex Codes, Color Order and Scatter

How to set MATLAB plot color: line Color formats, hex codes, the colororder palettes, scatter color inputs and axis colors, with a table of what works where.

Written and maintained by CASRAI Editorial Board

Last updated

In short: in MATLAB you set the color of a plotted line with the Color property, given as an RGB triplet in the range [0,1], a hexadecimal code, a color name or a short name. Colors for several lines come from the axes color order, which you change with colororder. Scatter points take color through the c argument or the marker color properties. This page is for researchers and analysts who need a figure to show the right colors, and it follows the MathWorks documentation read on 2026-11-07.

What plot color control is used for in research

Figures in papers and posters usually need series that stay distinguishable and match a journal or lab style. MATLAB has two separate ways to color a graph, and mixing them up is the usual source of confusion:

  • Fixed colors for lines, markers and axes, set directly (this page).
  • Data-mapped color, where values are mapped through a colormap. That is covered in MATLAB colormap colors.

Install or access

MATLAB is a MathWorks product; installation and licensing options are on mathworks.com. The commands below are core MATLAB graphics functions documented in the references at the end.

Step-by-step: color a line plot

  1. Create the plot. x = 0:0.1:2*pi; p = plot(x, sin(x)); The returned object p is the line.
  2. Set the color in the call or afterwards. Either plot(x, sin(x), 'Color', [0.4 0.6 0.7]) or p.Color = [0.4 0.6 0.7];
  3. Use a hex code or a name if you prefer. p.Color = '#0072BD'; or p.Color = 'red'; or p.Color = 'r';
  4. Color the markers separately if you use them: p.Marker = 'o'; p.MarkerEdgeColor = 'k'; p.MarkerFaceColor = [0.8 0.8 0.8];

Which color formats MATLAB accepts

For the Color property of a line the documentation lists four forms: an RGB triplet, a hexadecimal color code, a color name, or a short name. RGB intensities must be in [0,1], for example [0.4 0.6 0.7]. A hexadecimal code starts with # followed by three or six hexadecimal digits and is not case sensitive. The eight named colors are:

Color name Short name RGB triplet Hex
red r [1 0 0] #FF0000
green g [0 1 0] #00FF00
blue b [0 0 1] #0000FF
cyan c [0 1 1] #00FFFF
magenta m [1 0 1] #FF00FF
yellow y [1 1 0] #FFFF00
black k [0 0 0] #000000
white w [1 1 1] #FFFFFF

Source: MathWorks, Line Properties, read 2026-11-07. If you work from 0-255 values, divide each by 255 to get the [0,1] triplet.

How to color the lines of a multi-line plot: the color order

When you do not give a color, MATLAB takes each new line’s color from the axes color order. Several rules from the colororder documentation matter in practice:

  • colororder(colorarray) sets the order from an n-by-3 RGB matrix, colororder(palettename) sets it from a named palette, and C = colororder returns the current order.
  • With no target, the change applies to the current figure and every axes in it. With an axes as the target, only that axes changes.
  • Passing an explicit color in the plot call bypasses the color order for that line.
  • For a plot with two y-axes, set the figure’s color order before calling yyaxis to color each side.
  • Changing ColorOrderIndex does not alter lines that already exist; it takes effect after hold on and a further plotting call.
colororder("reef")plot(rand(5,4))

Built-in palettes

orderedcolors(palettename) returns the palette as RGB rows in [0,1]. The documented palette names are:

Palette Note from the documentation
gem Default for the light theme; "default" in colororder means gem
gem12 Twelve-color version of gem
glow Default for the dark theme
glow12 Twelve-color version of glow
sail, reef, meadow, dye, earth Other named palettes

To read the actual RGB values (for example to match a figure to a slide template), call C = orderedcolors("gem12"). To use a subset, index the rows: colororder(C(8:12,:)).

How to color a scatter plot

In scatter(x,y,sz,c), c can be a color name or short name, a single RGB triplet, an m-by-3 matrix with one color per point, or a numeric vector that is mapped into the current colormap (see the colormap guide). The "filled" option sets MarkerFaceColor to flat and MarkerEdgeColor to none. Hexadecimal codes are not listed for c; they are documented for the MarkerEdgeColor and MarkerFaceColor name-value arguments.

scatter(x, y, 40, 'MarkerFaceColor', '#0072BD', 'MarkerEdgeColor', 'k')

Decision table: where each color input works

Function and argument RGB triplet Hex code Name or short name Other
Line Color Yes Yes Yes –
Scatter c Yes Not listed Yes m-by-3 matrix; numeric vector via colormap
Axes XColor / YColor Yes Yes Yes –

Marker color on lines: MarkerFaceColor set to "none" gives no fill and "auto" fills with the figure color; MarkerEdgeColor set to "auto" uses the line’s Color. The default marker is none.

How to color an axis in MATLAB?

Set the axes properties on the current axes object. XColor, YColor and ZColor control the color of the axis line, tick values and labels, and the same color also applies to the grid lines unless you set GridColor or MinorGridColor. Color sets the axes background. Each accepts an RGB triplet, hexadecimal code, color name or short name.

ax = gca;ax.XColor = [1 1 0];ax.YColor = '#FFFF00';ax.Color = 'blue';ax.GridColor = 'b';

The box outline is colored with XColor, YColor and ZColor as well (source: MathWorks, Axes Properties, read 2026-11-07).

Output and how to read it

After a color change, check the figure rather than the code: lines created before a color-order change keep their old colors, and a line given an explicit Color ignores the order. Use C = colororder to see what the axes will use for the next line.

Troubleshooting

  • The new color order did not change my existing lines. Color order applies to lines drawn afterward. Re-plot, or set Color on each existing line.
  • Error with RGB values such as 255. RGB intensities must be in [0,1]; divide by 255.
  • Hex code not accepted as scatter’s c. Use MarkerFaceColor or MarkerEdgeColor with the hex code, or convert the hex to an RGB triplet.
  • Second y-axis has the wrong color. Set the color order on the figure before yyaxis.
  • Setting ColorOrderIndex seems to do nothing. It takes effect after hold on and another plotting call.

What colors work well for graphs?

The documentation does not prescribe one best color set, but it supplies ready-made palettes: gem and glow (and their 12-color forms) are the defaults for the light and dark themes, and sail, reef, meadow, dye and earth can be loaded with colororder. Choosing among them is an editorial decision: check the target journal’s figure instructions, and consider also varying line style or marker shape so series stay distinguishable if the figure is printed in grayscale. For the structural parts of a figure, see figure legend, and for chart design examples see great data visualization examples.

How to display a plot in MATLAB?

Calling plot or scatter opens a figure window and draws the graph in the current axes; use hold on to add more lines to the same axes. The basics are in MATLAB graph plot.

How to use a colormap in MATLAB?

A colormap assigns colors to data values, as with surfaces, images and scatter plots whose c is a numeric vector. It does not set the color of an ordinary line. Colormap functions and examples are in MATLAB colormap colors.

Free alternatives

Tool Related CASRAI guide
Python with Matplotlib Matplotlib line width
R with ggplot2 ggplot point shapes

The color values in the MATLAB tables above do not transfer automatically; use each tool’s own documentation for the syntax it accepts.

FAQ

What color formats does the MATLAB line Color property accept?

An RGB triplet in [0,1], a hexadecimal code beginning with #, one of eight color names, or the matching short name.

How do I give every line a different color?

Leave the color unspecified and set the palette with colororder; MATLAB cycles through the order for each new line.

Can I use hex codes in a scatter plot?

Yes for MarkerFaceColor and MarkerEdgeColor; the documentation does not list hex for the c argument.

How do I color an axis?

Set XColor, YColor or ZColor on the axes object.

Sources (official documentation, read 2026-11-07)

Follow CASRAI

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

Ask CASRAI · free to try

Ask about MATLAB Plot Color: Line Color, Hex Codes, Color Order and Scatter

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 →