subscript in ylabels of heatmap

2 views (last 30 days)
Rt Ro
Rt Ro on 12 Feb 2020
Edited: Subhadeep Koley on 12 Feb 2020
Hi
I want to write a word with subscription in ylabel of the heatmap.
but is shows: A_b
how can I edit this?
how can I show the xlable values as yearly (1971,1972,...)?
tbl = readtable('heatmap.test.xlsx');
t1 = datetime(1971,1,1);t2 = datetime(1986,12,1);
t = t1:calmonths(1):t2;t= t(:);
xlabels = string(datestr(t,12));
ylabels = {'A_b' 'B_b' 'C_b' 'D_b'};
cdata = tbl{:,2:5};
h = heatmap(xlabels,ylabels,cdata');
idx = [true;diff(year(t))] ~=0; % index of datetime values to show as x tick
h.XDisplayLabels(~idx) = {''};

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 12 Feb 2020
Starting in R2019a, heatmaps interpret text using TeX markup instead of displaying the literal characters. Therefore it seems you are using a release earlier than R2019a. Therefore, upgrading to the latest release might help!
For displaying "xlable values as yearly (1971,1972,...)" use the code below
close all; clc;
tbl = readtable('heatmapTest.xlsx');
t1 = datetime(1971,1,1);t2 = datetime(1986,12,1);
t = t1:calmonths(1):t2;t= t(:);
xlabels = string(datestr(t,10));
xlabels = char(xlabels);
xlabels = cellstr(xlabels);
ylabels = {'A_b' 'B_b' 'C_b' 'D_b'};
cdata = tbl{:,2:5};
h = heatmap(cdata');
h.XDisplayLabels = xlabels;
h.YDisplayLabels = ylabels;
idx = [true;diff(year(t))] ~=0;
h.XDisplayLabels(~idx) = {''};
  2 Comments
Rt Ro
Rt Ro on 12 Feb 2020
Thank you so much.
the code works well.
do you think the subscription in R2018b does not work for the heatmap?
Subhadeep Koley
Subhadeep Koley on 12 Feb 2020
Edited: Subhadeep Koley on 12 Feb 2020
You need to upgrade to at least R2019a to avail the tex markup feature in the function heatmap. tex markup for heatmap was not supported until R2019a.

Sign in to comment.

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!