pcolor
Pseudocolor plot
Description
pcolor( creates a pseudocolor plot using the values in matrixC)C. A pseudocolor plot displays matrix data as an array of colored cells (known asfaces). MATLAB® creates this plot as a flat surface in thex-y plane. The surface is defined by a grid ofx- andy-coordinates that correspond to the corners (or vertices) of the faces. The grid covers the regionX=1:n andY=1:m, where[m,n] = size(C). MatrixC specifies the colors at the vertices. The color of each face depends on the color at one of its four surrounding vertices. Of the four vertices, the one that comes first in thex-y grid determines the color of the face.
pcolor(___, sets properties of the plot using one or more name-value arguments. For example, you can specify the color or hide the mesh lines of the plot. For a list of properties, seeSurface Properties. (since R2024b)Name=Value)
pcolor( specifies the target axes for the plot. Specifyax,___)ax as the first argument in any of the previous syntaxes.
s = pcolor(___) returns aSurface object. Uses to set properties on the plot after creating it. For a list of properties, seeSurface Properties.
Examples
Create coordinate vectorsX andY and a colormap calledmymap containing five colors: red, green, blue, yellow, and black.
X = [1 2 3; 1 2 3; 1 2 3];Y = X';mymap = [1 0 0; 0 1 0; 0 0 1; 1 1 0; 0 0 0];
Create matrixC that maps the colormap colors to the nine vertices. Four of the nine vertices determine the colors of the faces. Specify the colors at those vertices to make the faces red (1), green (2), blue (3), and yellow (4), respectively. Set the colors at the other vertices to black (5).
C = [3 4 5; 1 2 5; 5 5 5];
Plot the faces, and call thecolormap function to replace the default colormap withmymap.
pcolor(X,Y,C)colormap(mymap)

A Hadamard matrix has elements that are either1 or-1. A good way to visualize this matrix is with a two-color colormap.
Create a 20-by-20 Hadamard matrix. Then plot the matrix using a black and white colormap. Use theaxis function to reverse the direction of they-axis and set the axis lines to equal lengths.
C = hadamard(20);pcolor(C)colormap(gray(2))axisijaxissquare

Create color matrixC. Then create a pseudocolor plot ofC, and store theSurface object in the return arguments.
C = [1 2 3; 4 5 6; 7 8 9];s = pcolor(C);

Change the border color by setting theEdgeColor property ofs. Make the border thicker by setting theLineWidth property.
s.EdgeColor = [1 0.7 0.3];s.LineWidth = 6;

Create color matrixC. Then create a pseudocolor plot ofC, and store theSurface object in the return arguments.
C = [5 13 9 7 12; 11 2 14 8 10; 6 1 3 4 15];s = pcolor(C);

To interpolate the colors across the faces, set theFaceColor property ofs to'interp'.
s.FaceColor ='interp';
Create matricesX andY, which define a regularly spaced grid of vertices. Calculate matrixLY as the log ofY. Then create matrixC containing alternating pairs of rows of color indices.
[X,Y] = meshgrid(1:20);LY = log(Y);colorscale = [1:20; 20:-1:1];C = repmat(colorscale,10,1);
PlotX andLY, using the colors specified inC. Then adjust the tick labels on they-axis.
s = pcolor(X,LY,C);tickvals = LY(2:2:20,1)';set(gca,'YTick',tickvals);
Create matricesX andY, which define a regularly spaced grid of vertices. Calculate matricesXX andYY as functions ofX andY. Then create matrixC containing alternating pairs of rows of color indices.
[X,Y] = meshgrid(-3:6/17:3);XX = 2*X.*Y;YY = X.^2 - Y.^2;colorscale = [1:18; 18:-1:1];C = repmat(colorscale,9,1);
PlotXX andYY using the colors inC.
pcolor(XX,YY,C);

Call thetiledlayout function to create a 1-by-2 tiled chart layout. Call thenexttile function to create the axes objectsax1 andax2. Create two pseudocolor plots by specifying the axes as the first argument topcolor.
tiledlayout(1,2)% Left plotax1 = nexttile;C1 = rand(20,10);pcolor(ax1,C1)% Right plotax2 = nexttile;C2 = rand(50,10);pcolor(ax2,C2)

Input Arguments
Color matrix containing indices into the colormap. The values inC map colors in the colormap array to the vertices surrounding each face. The color of a face depends on the color at one of its four vertices. Of the four vertices, the one that come first inX andY determines the color of the face. If you do not specifyX andY, MATLAB usesX=1:n andY=1:m, where[m,n] = size(C). Because of this relationship between the vertex colors and face colors, none of the values in the last row and column ofC are represented in the plot.

Note
The first vertex of a face is the one that is closest to the upper-left corner of the corresponding matrix. However, because they-axis increases from bottom to top, the first vertex shown in the plot is typically the one in the lower-left corner of the face. To get the effect you want, you might have to change the orientation of they-axis or the orientation of matrixC.
For a simple example that shows the relationship between the colors of the vertices and the faces, seePlot Four Faces with Four Colors.
The values inC scale to the full range of the colormap. The smallest value inC maps to the first row in the colormap array. The largest value inC maps to the last row in the colormap array. The intermediate values inC map linearly to the intermediate rows of the colormap array. You can adjust this mapping using theclim function.
Before R2022a: Use thecaxis function, which has the same syntaxes and arguments asclim.
TheCData property of theSurface object stores the values ofC.
Data Types:single |double |int8 |int16 |int32 |int64 |uint8 |uint16 |uint32 |uint64
x-coordinates, specified as a matrix the same size asC, or as a vector of lengthn, where[m,n] = size(C). The default value ofX is the vector(1:n).
To create a rectangular grid of vertices, specifyX as either of the following:
A vector containing values that are increasing or decreasing.
A matrix that is increasing or decreasing along one dimension and is constant along the other dimension. Set the dimension that varies to the opposite of the dimension that varies in matrix
Y. You can use themeshgridfunction to create theXandYmatrices.
To create a parametric grid, create a rectangular grid and pass it through a mathematical function.
Example:X = 1:10
Example:X = [1 2 3; 1 2 3; 1 2 3]
Example:[X,Y] = meshgrid(1:10)
TheXData property of theSurface object stores thex-coordinates.
Data Types:single |double |int8 |int16 |int32 |int64 |uint8 |uint16 |uint32 |uint64 |categorical |datetime |duration
y-coordinates, specified as a matrix the same size asC, or as a vector of lengthm, where[m,n] = size(C). The default value ofY is the vector(1:m).
To create a rectangular grid of vertices, specifyY as either of the following:
A vector containing values that are increasing or decreasing.
A matrix that is increasing or decreasing along one dimension and is constant along the other dimension. Set the dimension that varies to the opposite of the dimension that varies in matrix
X. You can use themeshgridfunction to create theXandYmatrices.
To create a parametric grid, create a rectangular grid and pass it through a mathematical function.
Example:Y = 1:10
Example:Y = [1 1 1; 2 2 2; 3 3 3]
Example:[X,Y] = meshgrid(1:10)
TheYData property of theSurface object stores they-coordinates.
Data Types:single |double |int8 |int16 |int32 |int64 |uint8 |uint16 |uint32 |uint64 |categorical |datetime |duration
Axes to plot into, specified as anAxes orPolarAxes object. If you do not specify the axes, thenpcolor plots into the current axes or creates anAxes object (Cartesian axes).
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereName is the argument name andValue is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Example:pcolor([1 2 3; 4 5 6; 7 8 9],FaceColor="interp") interpolates the color across the faces.
Note
The properties listed here are only a subset. For a full list, seeSurface Properties.
Face color, specified as one of the values in this table.
| Value | Description |
|---|---|
'flat' | Use a different color for each face based on the valuesin the
|
'interp' | Use interpolated coloring for each face based on the values in the
|
| RGB triplet, hexadecimal color code, or color name | Use the specified color for all the faces. This option does not use the color values in the
|
'texturemap' | Transform the color data inCData so thatit conforms to the surface. |
'none' | Do not draw the faces. |
RGB triplets and hexadecimal color codes are useful for specifying custom colors.
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range
[0,1]; for example,[0.4 0.6 0.7].A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (
#) followed by three or six hexadecimal digits, which can range from0toF. The values are not case sensitive. Thus, the color codes"#FF8800","#ff8800","#F80", and"#f80"are equivalent.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
| Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
|---|---|---|---|---|
"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" |
|
This table lists the default color palettes for plots in the light and dark themes.
| Palette | Palette Colors |
|---|---|
Before R2025a: Most plots use these colors by default. |
|
|
|
You can get the RGB triplets and hexadecimal color codes for these palettes using theorderedcolors andrgb2hex functions. For example, get the RGB triplets for the"gem" palette and convert them to hexadecimal color codes.
RGB = orderedcolors("gem");H = rgb2hex(RGB);Before R2023b: Get the RGB triplets usingRGB = get(groot,"FactoryAxesColorOrder").
Before R2024a: Get the hexadecimal color codes usingH = compose("#%02X%02X%02X",round(RGB*255)).
Edge line color, specified as one of the values listed in this table.
| Value | Description |
|---|---|
'none' | Do not draw the edges. |
'flat' | Use a different color for each edge based on the valuesin the
|
'interp' | Use interpolated coloring for each edge based on the values in the
|
| RGB triplet, hexadecimal color code, or color name | Use the specified color for all the edges. This option does not use the color values in the
|
RGB triplets and hexadecimal color codes are useful for specifying custom colors.
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range
[0,1]; for example,[0.4 0.6 0.7].A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (
#) followed by three or six hexadecimal digits, which can range from0toF. The values are not case sensitive. Thus, the color codes"#FF8800","#ff8800","#F80", and"#f80"are equivalent.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
| Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
|---|---|---|---|---|
"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" |
|
This table lists the default color palettes for plots in the light and dark themes.
| Palette | Palette Colors |
|---|---|
Before R2025a: Most plots use these colors by default. |
|
|
|
You can get the RGB triplets and hexadecimal color codes for these palettes using theorderedcolors andrgb2hex functions. For example, get the RGB triplets for the"gem" palette and convert them to hexadecimal color codes.
RGB = orderedcolors("gem");H = rgb2hex(RGB);Before R2023b: Get the RGB triplets usingRGB = get(groot,"FactoryAxesColorOrder").
Before R2024a: Get the hexadecimal color codes usingH = compose("#%02X%02X%02X",round(RGB*255)).
Line style, specified as one of the options listed in this table.
| Line Style | Description | Resulting Line |
|---|---|---|
"-" | Solid line |
|
"--" | Dashed line |
|
":" | Dotted line |
|
"-." | Dash-dotted line |
|
"none" | No line | No line |
Algorithms
Use thepcolor,image, andimagesc functions to display rectangular arrays of colored cells. The relationship between the color matrixC and the colored cells is different in each case.
pcolor(C)uses the values inCto define the vertex colors by scaling the values to the full range of the colormap. The size ofCdetermines the number of vertices. The values inCmap colors from the current colormap to the vertices surrounding each cell.image(C)usesCto define the cell colors by mapping the values directly into the colormap. The size ofCdetermines the number of cells.imagesc(C)usesCto define the cell colors by scaling the values to the full range of the colormap. The size ofCdetermines the number of cells.
Extended Capabilities
Thepcolor function supports GPU array input with these usage notes and limitations:
This function accepts GPU arrays, but does not run on a GPU.
For more information, seeRun MATLAB Functions on a GPU (Parallel Computing Toolbox).
Usage notes and limitations:
This function operates on distributed arrays, but executes in the client MATLAB.
For more information, seeRun MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aCreate pseudocolor plot in polar coordinates by specifying aPolarAxes object as the first argument.
Control the appearance and behavior of pseudocolor plots by specifying name-value arguments. Previously,pcolor did not support name-value arguments.
See Also
Functions
Properties
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)




















