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';
Title
— Title''
(default) | character vector | string scalarTitle 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'
XLabel
— Label for x-axis'Predicted class'
(default) | string scalar | character vectorLabel for the x-axis, specified as a string scalar or character vector.
Example: cm = confusionchart(__,'XLabel','My
Label')
Example: cm.XLabel = 'My Label'
YLabel
— Label for y-axis'True class'
(default) | string scalar | character vectorLabel for the x-axis, specified as a string scalar or character vector.
Example: cm = confusionchart(__,'YLabel','My
Label')
Example: cm.YLabel = 'My Label'
ClassLabels
— Class labelsThis 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.
ColumnSummary
— Column summary'off'
(default) | 'absolute'
| 'column-normalized'
| 'total-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'
RowSummary
— Row summary'off'
(default) | 'absolute'
| 'row-normalized'
| 'total-normalized'
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'
NormalizedValues
— Values of the confusion matrixThis 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
— Normalization of cell values'absolute'
(default) | 'column-normalized'
| 'row-normalized'
| 'total-normalized'
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'
GridVisible
— State of grid visibility'on'
(default) | on/off logical valueState 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'
DiagonalColor
— Color for diagonal cells[0 0.4471 0.7412]
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...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 from 0
to F
. 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' |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] | '#0072BD' | |
[0.8500 0.3250 0.0980] | '#D95319' | |
[0.9290 0.6940 0.1250] | '#EDB120' | |
[0.4940 0.1840 0.5560] | '#7E2F8E' | |
[0.4660 0.6740 0.1880] | '#77AC30' | |
[0.3010 0.7450 0.9330] | '#4DBEEE' | |
[0.6350 0.0780 0.1840] | '#A2142F' |
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'
OffDiagonalColor
— Color for off-diagonal cells[0.8510 0.3255 0.0980]
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...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 from 0
to F
. 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' |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] | '#0072BD' | |
[0.8500 0.3250 0.0980] | '#D95319' | |
[0.9290 0.6940 0.1250] | '#EDB120' | |
[0.4940 0.1840 0.5560] | '#7E2F8E' | |
[0.4660 0.6740 0.1880] | '#77AC30' | |
[0.3010 0.7450 0.9330] | '#4DBEEE' | |
[0.6350 0.0780 0.1840] | '#A2142F' |
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'
FontColor
— Text color for title, axis labels, and class labels[0.1500 0.1500 0.1500]
(default) | RGB triplet | hexadecimal color code | 'r'
| 'g'
| 'b'
| ...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 from 0
to F
. 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' |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] | '#0072BD' | |
[0.8500 0.3250 0.0980] | '#D95319' | |
[0.9290 0.6940 0.1250] | '#EDB120' | |
[0.4940 0.1840 0.5560] | '#7E2F8E' | |
[0.4660 0.6740 0.1880] | '#77AC30' | |
[0.3010 0.7450 0.9330] | '#4DBEEE' | |
[0.6350 0.0780 0.1840] | '#A2142F' |
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'
FontName
— Font nameFont 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'
FontSize
— Font sizeFont 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
PositionConstraint
— Position to hold constant'outerposition'
| 'innerposition'
Position property to hold constant when adding, removing, or changing decorations, specified as one of the following values:
'outerposition'
— The OuterPosition
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 the InnerPosition
property.
'innerposition'
— The InnerPosition
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 the OuterPosition
property.
Note
Setting this property has no effect when the parent container is a
TiledChartLayout
.
OuterPosition
— Outer size and position[0 0 1 1]
(default) | four-element vectorOuter 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
and bottom
elements define the
distance from the lower left corner of the container to the lower left corner of
the chart.
The width
and height
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]
InnerPosition
— Inner size and position[0.1300 0.1100 0.7750 0.8150]
(default) | four-element vectorInner 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
and bottom
elements define the
distance from the lower left corner of the container to the lower left corner of
the chart.
The width
and height
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]
Position
— Inner size and positionInner 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.
Units
— Position units'normalized'
(default) | 'inches'
| 'centimeters'
| 'points'
| 'pixels'
| 'characters'
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. Starting in R2015b, distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
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
— Layout optionsLayoutOptions
array (default) | TiledChartLayoutOptions
object | GridLayoutOptions
objectLayout 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.
Visible
— State of visibility'on'
(default) | on/off logical valueState 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
— Parent containerFigure
object | Panel
object | Tab
object | TiledChartLayout
object | GridLayout
objectParent container, specified as a Figure
,
Panel
, Tab
,
TiledChartLayout
, or GridLayout
object.
HandleVisibility
— Visibility of object handle'on'
(default) | 'off'
| 'callback'
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 the HandleVisibility
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.