To create a heatmap with both a categorical color scale and a quantitative color scale in MATLAB:
heatmap
function in MATLAB.colormap
function to set a color-mapping function for both the categorical and quantitative scales.Colorbar
function to add a color bar that indicates the scale of each color.Here is an example code snippet to create a heatmap with categorical color scale and quantitative color scale in MATLAB:
main.m602 chars25 lines
In this example, the categorical variable is the number of cylinders (converted to a categorical variable with only three categories), and the quantitative variable is the horsepower. The weight represents the vertical axis, and MPG represents the data values.
The jet
colormap is used to map the quantitative color data, and the discrete color categories are defined using a separate categorical variable.
The heatmap
function is used to create the heatmap, with the ColorMethod
set to 'quantile', which allows the heatmap to use the full range of the colormap. The ColorData
parameter is used to specify the colors for each value in the heatmap based on the quantitative data. The colorbar
function is used to show the color scale. The xlabel
and ylabel
functions are used to label the x-axis and y-axis, respectively.
gistlibby LogSnag