ConfusionMatrixChart Properties
Confusion matrix chart appearance and behavior
ConfusionMatrixChart
properties control the
appearance and behavior of a ConfusionMatrixChart
object. By
changing property values, you can modify certain aspects of the confusion matrix chart. For
example, you can add a title:
cm = confusionchart([1 3 5; 2 4 6; 11 7 3]);
cm.Title = 'My Confusion Matrix Title';
Labels
Title of the confusion matrix chart, specified as a character vector or string scalar.
Example: cm = confusionchart(__,'Title','My Title
Text')
Example: cm.Title = 'My Title Text'
Label for the x-axis, specified as a string scalar or character vector.
Example: cm = confusionchart(__,'XLabel','My
Label')
Example: cm.XLabel = 'My Label'
Label for the x-axis, specified as a string scalar or character vector.
Example: cm = confusionchart(__,'YLabel','My
Label')
Example: cm.YLabel = 'My Label'
This property is read-only.
Class labels of the confusion matrix chart, stored as a categorical vector, numeric vector, string vector, character array, cell array of character vectors, or logical vector.
Since R2025a
Labels for the row (y-axis) values, specified as
a string array, categorical array, or cell array of character vectors. The array must be
the same size as ClassLabels
. By default, the labels are a string
array created from the ClassLabels
value. When you specify this
property as a categorical array, MATLAB® uses the values in the array, not the categories.
The order of RowDisplayLabels
must match the order of
ClassLabels
. By default, confusionchart
sorts
the classes into their natural order as defined by sort
. If you
specify RowDisplayLabels
when you call the
confusionchart
function, then the order must match the order
defined by calling sort
on the true and predicted labels. If you
specify RowDisplayLabels
after you have created the
ConfusionMatrixChart
object, then the order must match the order of
cm.ClassLabels
.
Example: cm.RowDisplayLabels = ["SM","MED","LG"]
Example: cm =
confusionchart(__,'RowDisplayLabels',["SM","MED","LG"])
Data Types: char
| string
| cell
| categorical
Since R2025a
Labels for the column (x-axis) values, specified
as a string array, categorical array, or cell array of character vectors . The array
must be the same size as ClassLabels
. By default, the labels are a
string array created from the ClassLabels
value. When you specify
this property as a categorical array, MATLAB uses the values in the array, not the categories.
The order of ColumnDisplayLabels
must match the order of
ClassLabels
. By default, confusionchart
sorts
the classes into their natural order as defined by sort
. If you
specify ColumnDisplayLabels
when you call the
confusionchart
function, then the order must match the order of
the ClassLabels
input argument. If you specify
ColumnDisplayLabels
after you have created the
ConfusionMatrixChart
object, then the order must match the order of
cm.ClassLabels
.
Example: cm.ColumnDisplayLabels = ["SM","MED","LG"]
Example: cm =
confusionchart(__,'ColumnDisplayLabels',["SM","MED","LG"])
Data Types: char
| string
| cell
| categorical
Since R2025a
State of summary labels visibility, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A value
of 'on'
is equivalent to true
, and
'off'
is equivalent to false
. Thus, you can use
the value of this property as a logical value. The value is stored as an on/off logical
value of type matlab.lang.OnOffSwitchState
.
'on'
— Display labels for the true positive rate (TPR), false negative rate (FNR), positive predictive value (PPV), and false discovery rate (FDR) on the row and column summaries.'off'
— Do not display labels on the row and column summaries.
Example: cm =
confusionchart(__,'SummaryLabelsVisible','on')
Example: cm.SummaryLabelsVisible = 'on'
Since R2025a
Text interpreter, specified as one of these values:
'tex'
— Interpret characters using a subset of TeX markup.'latex'
— Interpret characters using LaTeX markup.'none'
— Display literal characters.
The confusionchart
function uses the interpreter when
displaying the chart title, axis labels, or any data that includes text or symbols.
Before R2025a: Confusion charts interpret characters using a subset of TeX markup.
TeX Markup
By default, MATLAB supports a subset of TeX markup. Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the text.
Modifiers remain in effect until the end of the
text. Superscripts and subscripts are an exception because they modify only the next
character or characters within curly braces. This table lists the supported modifiers
for the "tex"
interpreter.
Modifier | Description | Example |
---|---|---|
^{ } | Superscript | "text^{superscript}" |
_{ } | Subscript | "text_{subscript}" |
\bf | Bold font | "\bf text" |
\it | Italic font | "\it text" |
\sl | Oblique font (usually the same as italic font) | "\sl text" |
\rm | Normal font | "\rm text" |
\fontname{ | Font name — Replace
with the name of
a font family. You can use this in combination with other modifiers. | "\fontname{Courier} text" |
\fontsize{ | Font size —Replace
with a numeric
scalar value in point units. | "\fontsize{15} text" |
\color{ | Font color — Replace
with one of
these colors: red , green ,
yellow , magenta ,
blue , black ,
white , gray ,
darkGreen , orange , or
lightBlue . | "\color{magenta} text" |
\color[rgb]{specifier} | Custom font color — Replace
with a
three-element RGB triplet. | "\color[rgb]{0,0.5,0.5} text" |
This table lists the supported special characters
for the "tex"
interpreter.
Character Sequence | Symbol | Character Sequence | Symbol | Character Sequence | Symbol |
---|---|---|---|---|---|
| α |
| υ |
| ~ |
| ∠ |
| ϕ |
| ≤ |
|
|
| χ |
| ∞ |
| β |
| ψ |
| ♣ |
| γ |
| ω |
| ♦ |
| δ |
| Γ |
| ♥ |
| ϵ |
| Δ |
| ♠ |
| ζ |
| Θ |
| ↔ |
| η |
| Λ |
| ← |
| θ |
| Ξ |
| ⇐ |
| ϑ |
| Π |
| ↑ |
| ι |
| Σ |
| → |
| κ |
| ϒ |
| ⇒ |
| λ |
| Φ |
| ↓ |
| µ |
| Ψ |
| º |
| ν |
| Ω |
| ± |
| ξ |
| ∀ |
| ≥ |
| π |
| ∃ |
| ∝ |
| ρ |
| ∍ |
| ∂ |
| σ |
| ≅ |
| • |
| ς |
| ≈ |
| ÷ |
| τ |
| ℜ |
| ≠ |
| ≡ |
| ⊕ |
| ℵ |
| ℑ |
| ∪ |
| ℘ |
| ⊗ |
| ⊆ |
| ∅ |
| ∩ |
| ∈ |
| ⊇ |
| ⊃ |
| ⌈ |
| ⊂ |
| ∫ |
| · |
| ο |
| ⌋ |
| ¬ |
| ∇ |
| ⌊ |
| x |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
LaTeX Markup
To use LaTeX markup, set the interpreter to 'latex'
. For inline
mode, surround the markup with single dollar signs ($
). For display
mode, surround the markup with double dollar signs ($$
).
The displayed text uses the default LaTeX font style. To change the font style, use LaTeX markup.
The maximum size of the text that you can use with the LaTeX interpreter is 1200 characters. For multiline text, this reduces by about 10 characters per line.
For examples that use TeX and LaTeX, see Greek Letters and Special Characters in Chart Text. For more information about the LaTeX system, see The LaTeX Project website at https://www.latex-project.org/.
Row and Column Summaries
Row summary of the confusion matrix chart, specified as one of the following:
Option | Description |
---|---|
'off' | Do not display a row summary. |
'absolute' | Display the total number of correctly and incorrectly classified observations for each true class. |
'row-normalized' | Display the number of correctly and incorrectly classified observations for each true class as percentages of the number of observations of the corresponding true class. The percentages of correctly classified observations can be thought of as class-wise recalls (or true positive rates). |
'total-normalized' | Display the number of correctly and incorrectly classified observations for each true class as percentages of the total number of observations. |
Example: cm = confusionchart(__,'RowSummary','row-normalized')
Example: cm.RowSummary = 'row-normalized'
Column summary of the confusion matrix chart, specified as one of the following:
Option | Description |
---|---|
'off' | Do not display a column summary. |
'absolute' | Display the total number of correctly and incorrectly classified observations for each predicted class. |
'column-normalized' | Display the number of correctly and incorrectly classified observations for each predicted class as percentages of the number of observations of the corresponding predicted class. The percentages of correctly classified observations can be thought of as class-wise precisions (or positive predictive values). |
'total-normalized' | Display the number of correctly and incorrectly classified observations for each predicted class as percentages of the total number of observations. |
Example: cm = confusionchart(__,'ColumnSummary','column-normalized')
Example: cm.ColumnSummary = 'column-normalized'
Data
This property is read-only.
Values of the confusion matrix, stored as a numeric matrix. This property equals the
values of the confusion matrix normalized using the method of the
Normalization
property. The software recalculates the normalized
values of the confusion matrix each time you modify the
Normalization
property.
Normalization of cell values, specified as one of the following:
Option | Description |
---|---|
'absolute' | Display the total number of observations in each cell. |
'column-normalized' | Normalize each cell value by the number of observations that has the same predicted class. |
'row-normalized' | Normalize each cell value by the number of observations that has the same true class. |
'total-normalized' | Normalize each cell value by the total number of observations. |
Modifying the normalization of cell values also affects the colors of the cells.
Example: cm = confusionchart(__,'Normalization','total-normalized')
Example: cm.Normalization = 'total-normalized'
Color and Styling
State of grid visibility, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A value
of 'on'
is equivalent to true, and 'off'
is
equivalent to false
. Thus, you can use the value of this property as
a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
'on'
— Display grid lines between the chart cells.'off'
— Do not display grid lines between the chart cells.
Example: cm =
confusionchart(__,'GridVisible','off')
Example: cm.GridVisible = 'off'
Color for diagonal cells, specified as an RGB triplet, a hexadecimal color code, a
color name, or a short name. The color of each diagonal cell is proportional to the cell
value and the DiagonalColor
property, normalized to the largest
cell value of the confusion matrix chart. Cells with positive values are colored with a
minimum amount of color, proportional to the DiagonalColor
property.
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 from0
toF
. 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 the orderedcolors
and rgb2hex
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 using RGB =
get(groot,"FactoryAxesColorOrder")
.
Before R2024a: Get the hexadecimal color codes using H =
compose("#%02X%02X%02X",round(RGB*255))
.
The software chooses an appropriate text color for cell labels automatically, depending on the color of the chart cells.
Example: cm =
confusionchart(__,'DiagonalColor','blue')
Example: cm.DiagonalColor = 'blue'
Color for off-diagonal cells, specified as an RGB triplet, a hexadecimal color code,
a color name, or a short name. The color of each diagonal cell is proportional to the
cell value and the OffDiagonalColor
property, normalized to the
largest cell value of the confusion matrix chart. Cells with positive values are colored
with a minimum amount of color, proportional to the
OffDiagonalColor
property.
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 from0
toF
. 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 the orderedcolors
and rgb2hex
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 using RGB =
get(groot,"FactoryAxesColorOrder")
.
Before R2024a: Get the hexadecimal color codes using H =
compose("#%02X%02X%02X",round(RGB*255))
.
The software chooses an appropriate text color for cell labels automatically, depending on the color of the chart cells.
Example: cm =
confusionchart(__,'OffDiagonalColor','blue')
Example: cm.OffDiagonalColor = 'blue'
Text color for title, axis labels, and class labels, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.
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 from0
toF
. 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 the orderedcolors
and rgb2hex
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 using RGB =
get(groot,"FactoryAxesColorOrder")
.
Before R2024a: Get the hexadecimal color codes using H =
compose("#%02X%02X%02X",round(RGB*255))
.
The software chooses an appropriate text color for cell labels automatically, depending on the color of the chart cells.
Example: cm = confusionchart(__,'FontColor','blue')
Example: cm.FontColor = 'blue'
Font
Font name, specified as a system supported font name. The default font depends on the specific operating system and locale.
Example: cm =
confusionchart(__,'FontName','Cambria')
Example: cm.FontName = 'Cambria'
Font size used for the title, axis labels, class labels, and cell labels, specified as a positive scalar. The default font depends on the specific operating system and locale.
The title and axis labels use a slightly larger font size (scaled up by 10%). If there is not enough room to display the cell labels within the cells, then the cell labels use a smaller font size. If the cell labels become too small, then they are hidden.
Example: cm = confusionchart(__,'FontSize',12)
Example: cm.FontSize = 12
Position
Position property to hold constant when adding, removing, or changing decorations, specified as one of the following values:
"outerposition"
— TheOuterPosition
property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts theInnerPosition
property."innerposition"
— TheInnerPosition
property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts theOuterPosition
property.
Note
Setting this property has no effect when the parent container is a
TiledChartLayout
object.
Outer size and position within the parent container (a figure, panel, or tab),
specified as a four-element vector of the form [left bottom width
height]
. The outer position includes the title, axis labels, and class
labels.
The
left
andbottom
elements define the distance from the lower left corner of the container to the lower left corner of the chart.The
width
andheight
elements are the chart dimensions, which include the chart cells, plus a margin for the surrounding text.
The default value of [0 0 1 1]
is the whole interior of the
container.
By default, the values are normalized to the container. To change the units, set the
Units
property.
Example: cm = confusionchart(__,'OuterPosition',[0.1 0.1 0.8
0.8])
Example: cm.OuterPosition = [0.1 0.1 0.8 0.8]
Inner size and position of the chart within the parent container (a figure, panel,
or tab) returned as a four-element vector of the form [left bottom width
height]
. The inner position does not include the title, axis labels, or
class labels.
The
left
andbottom
elements define the distance from the lower left corner of the container to the lower left corner of the chart.The
width
andheight
elements are the chart dimensions, which include only the chart cells.
Example: cm = confusionchart(__,'InnerPosition',[0.1 0.1 0.8
0.8])
Example: cm.InnerPosition = [0.1 0.1 0.8 0.8]
Inner size and position of the chart within the parent container (a figure, panel,
or tab) returned as a four-element vector of the form [left bottom width
height]
. This property is equivalent to the
InnerPosition
property.
Position units, specified as one of these values:
Units | Description |
---|---|
'normalized' | Normalized with respect to the container, which is typically the figure
or a panel. The lower left corner of the container maps to
(0,0) , and the upper right corner maps to
(1,1) . |
'inches' | Inches. |
'centimeters' | Centimeters. |
'characters' | Based on the default uicontrol font of the graphics root object:
|
'points' | Typography points. One point equals 1/72 inch. |
'pixels' | Pixels. On Windows® and Macintosh systems, the size of a pixel is 1/96th of an inch. This size is independent of your system resolution. On Linux® systems, the size of a pixel is determined by your system resolution. |
When specifying the units as a name-value pair during object creation, you must set
the Units
property before specifying the properties that you want
to use these units for, such as OuterPosition
.
Layout options, specified as a TiledChartLayoutOptions
or
GridLayoutOptions
object. This property is useful when the chart
is either in a tiled chart layout or a grid layout.
To position the chart within the grid of a tiled chart layout, set the
Tile
and TileSpan
properties on the
TiledChartLayoutOptions
object. For example, consider a 3-by-3
tiled chart layout. The layout has a grid of tiles in the center, and four tiles along
the outer edges. In practice, the grid is invisible and the outer tiles do not take up
space until you populate them with axes or charts.
This code places the chart c
in the third tile of the
grid.
c.Layout.Tile = 3;
To make the chart span multiple tiles, specify the TileSpan
property as a two-element vector. For example, this chart spans 2
rows and 3
columns of
tiles.
c.Layout.TileSpan = [2 3];
To place the chart in one of the surrounding tiles, specify the
Tile
property as "north"
,
"south"
, "east"
, or "west"
.
For example, setting the value to "east"
places the chart in the tile
to the right of the
grid.
c.Layout.Tile = "east";
To place the chart into a layout within an app, specify this property as a
GridLayoutOptions
object. For more information about working with
grid layouts in apps, see uigridlayout
.
If the chart is not a child of either a tiled chart layout or a grid layout (for example, if it is a child of a figure or panel) then this property is empty and has no effect.
State of visibility, specified as 'on'
or
'off'
, or as numeric or logical 1
(true
) or 0
(false
). A value
of 'on'
is equivalent to true, and 'off'
is
equivalent to false
. Thus, you can use the value of this property as
a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
'on'
— Display the chart.'off'
— Hide the chart without deleting it. You still can access the properties of an invisible chart.
Parent/Child
Parent container, specified as a Figure
,
Panel
, Tab
,
TiledChartLayout
, or GridLayout
object.
Visibility of the chart object handle in the Children
property of
the parent, specified as one of these values:
'on'
— Object handle is always visible.'off'
— Object handle is invisible at all times. This option is useful for preventing unintended changes to the UI by another function. To temporarily hide the handle during the execution of that function, set theHandleVisibility
to'off'
.'callback'
— Object handle is visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line. This option blocks access to the object at the command line, but allows callback functions to access it.
If the object is not listed in the Children
property of the
parent, then functions that obtain object handles by searching the object hierarchy or
querying handle properties cannot return it. This includes get
, findobj
, gca
, gcf
, gco
, newplot
, cla
, clf
, and close
.
Hidden object handles are still valid. Set the root
ShowHiddenHandles
property to 'on'
to list all
object handles, regardless of their HandleVisibility
property
setting.
Version History
Introduced in R2018bYou can now customize the titles and labels of ConfusionMatrixChart
objects:
Specify labels for the row (y-axis) and column (x-axis) values using the
RowDisplayLabels
andColumnDisplayLabels
properties.Interpret text labels, such as titles and axis labels, with TeX markup, LaTeX markup, or no markup using the
Interpreter
property.Before R2025a: All confusion charts have the interpreter set to
'tex'
for title and axis labels and 'none' for tick labels.Display labels for the true positive rate (TPR), false negative rate (FNR), positive predictive value (PPV), and false discovery rate (FDR) on the row and column summaries using the
SummaryLabelsVisible
property.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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: United States.
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)