Why does the heatmap chart color some numeric values differently?

10 views (last 30 days)
I want to understand why the heatmap chart color tabulated numbers differently. Does the white values represent high values? If you check the example below, you will see that 24 is colored in white while the other number remain in black. How can I control this coloring option based on custom conditions?
openExample('graphics/CreateHeatmapFromTabularDataExample')
  1 Comment
Thomas Shaw
Thomas Shaw on 26 Apr 2023
@chicken vector gives good advice: the handle h returned by a graphics command generally has useful hints about what you can customize about how it is displayed. Sometimes it's still not obvious what all of the available options are, though. In that case there is often more detailed documentation that you can access by
doc h
If you run that after the example you pointed to, and go down to the section about CellLabelColor, you will see
> Text color for data labels, specified as 'auto', an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of 'auto' chooses an appropriate text color, depending on the color of each heatmap cell. If you do not want the labels to display, specify 'none'.
So in other words, when this is set to auto (which is the default), it will choose a light color text for cells whose backgrounds are dark, and vice versa. It looks like there is no documented/straightforward way to choose particular colors for particular ranges of values.

Sign in to comment.

Answers (1)

chicken vector
chicken vector on 26 Apr 2023
Edited: chicken vector on 26 Apr 2023
>> h = heatmap(tbl,'Smoker','SelfAssessedHealthStatus','CellLabelColor','Black');
% ^----------------------^
A quick tip for next time.
After you create the heatmap stored in teh variable h, you type h in the command window and see all public properties of the object.
Typically, from the name of the properties you will easily find what you are looking for.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!