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
- Create the plot.
x = 0:0.1:2*pi; p = plot(x, sin(x));The returned objectpis the line. - Set the color in the call or afterwards. Either
plot(x, sin(x), 'Color', [0.4 0.6 0.7])orp.Color = [0.4 0.6 0.7]; - Use a hex code or a name if you prefer.
p.Color = '#0072BD';orp.Color = 'red';orp.Color = 'r'; - 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, andC = colororderreturns 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
plotcall bypasses the color order for that line. - For a plot with two y-axes, set the figure’s color order before calling
yyaxisto color each side. - Changing
ColorOrderIndexdoes not alter lines that already exist; it takes effect afterhold onand 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
Coloron 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. UseMarkerFaceColororMarkerEdgeColorwith 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
ColorOrderIndexseems to do nothing. It takes effect afterhold onand 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.







