Ruchik Yajnik
Ruchik Yajnik

Reputation: 329

MATLAB: How to add custom ticks and labels to an imagesc plot?

I have made a matrix containing 13 different vectors with ~300K+ rows. I have visualized the matrix by transposing it and using the imagesc function to see the distribution of colors. All vectors have been resampled, processed and normalized between 0 & 1 individually.

The imagesc plot gives me this result (fig 1): Normal imagesc plot

But, when I use the axis functionality to add x & y limits, I get this:

Solid colorbars

How do I maintain the imagesc plot while being able to add custom ticks and labels to the X & y axis? The x axis represents time, while the y axis will get its own labels with sensor names.

Upvotes: 2

Views: 4759

Answers (1)

Laure
Laure

Reputation: 373

You redefine limits from 0 to 30 on the x-axis while the initial xlimits goes up to 3e5. Same issue with the y-axis

Here's how to redefine the Y-axis to put sensor names:

C = [0 2 4 6 9 ; 8 10 12 44 14; 16 48 10 32 23];
image(C)
% Get axis handle
ax = gca;

% Set where ticks will be
ax.YTick = [1 2 3];
% Set TickLabels;
ax.YTickLabel = {'S1','S2','S3'};

Figure out the ax.YTick where you want the labels to appear.

If you want the x-axis to go from 0 to 30, divide the x component of all vectors by 1e4 before plotting. Alternatively, you can add the line:

ax.XTickLabel = ax.XTick/1e4;

Upvotes: 3

Related Questions