Documentation

caxis

Color axis scaling

Syntax

caxis([cmin cmax])
caxis auto
caxis manual
caxis(caxis)
v = caxis
caxis(target,...)

Description

caxiscontrols the mapping of data values to the colormap.

caxis([cmin cmax])sets the color limits for the current axes or chart returned by thegcacommand. Data values less thancminor greater thancmaxmap tocminandcmax, respectively. Values betweencminandcmaxlinearly map to the current colormap.

caxis autocomputes the color limits automatically using the minimum and maximum data values. This is the default behavior. Color values set toInfmap to the maximum color, and values set to -Infmap to the minimum color. Faces or edges with color values set toNaNare not drawn.

caxis manualandcaxis(caxis)freeze the color axis scaling at the current limits. This enables subsequent plots to use the same limits whenholdison.

v = caxisreturns a two-element row vector containing the[cmincmax]currently in use.

caxis(target,...)uses the axes or chart specified bytargetinstead of the current axes or chart.

Input Arguments

collapse all

Target, specified as anAxesobject or a graphics object that has aColorLimitsproperty. For example, you can set or query the color limits for aHeatmapChartobject.

If you do not specify the target, then thecaxisfunction uses the graphics object returned by thegcacommand.

ForAxesobjects,caxischanges theCLimandCLimModeproperties. It affects anysurface,patch, orimagewith indexedCDataandCDataMapping设置为扩展。它不影响表面,药物贴片s, or images with true colorCDataor withCDataMappingset todirect.

Examples

collapse all

DefineX,Y, andZas data for a sphere and view the data as a surface. Define the colors for the surface,C.

[X,Y,Z] = sphere; C = Z; surf(X,Y,Z,C)

Values ofCare in the range[1]. Values ofCnear -1 are assigned the lowest values in the colormap. Values ofCnear 1 are assigned the highest values in the colormap.

Map the top half of the surface to the highest value in the color table by setting the maximum color limit to 0.

caxis([-1,0])

Reset the axis scaling back to its default range.

caxisauto

Return the values of the current color limits.

v = caxis
v =-1 1

Load thecapefile which contains the image data,X, and the colormap,map, for Cape Cod, Massachusetts.

loadcape

Display the image withCDataMappingset toscaled, and use themapcolormap.

figure image(X,'CDataMapping','scaled') colormap(map)

The color limits span the range of the image data, which is 1 to 192. The blue color of the ocean is the first color in the colormap and is mapped to the lowest data value, 1. You can effectively move sea level by changing the lower color limit value usingcaxis.

Display the image data using four different color limit values.

loadcapefigure colormap(map) subplot(2,2,1) image(X,'CDataMapping','scaled') title('caxis = [1 192]') subplot(2,2,2) image(X,'CDataMapping','scaled') caxis([4,192])% change caxistitle('caxis = [4 192]') subplot(2,2,3) image(X,'CDataMapping','scaled') caxis([7,192])% change caxistitle('caxis = [7 192]') subplot(2,2,4) image(X,'CDataMapping','scaled') caxis([10,192])% change caxistitle('caxis = [10 192]')

Tips

How Color Axis Scaling Works

Surface, patch, and image graphics objects having indexedCDataandCDataMappingset toscaledmapCDatavalues to colors in the figure colormap each time they render.CDatavalues equal to or less thancminmap to the first color value in the colormap, andCDatavalues equal to or greater thancmaxmap to the last color value in the colormap. The following linear transformation is performed on the intermediate values (referred to asCbelow) to map them to an entry in the colormap (whose length ism, and whose row index is referred to asindexbelow).

index = fix((C-cmin)/(cmax-cmin)*m)+1; %Clamp values outside the range [1 m] index(index<1) = 1; index(index>m) = m;

Introduced before R2006a

Was this topic helpful?