shamalaia
shamalaia

Reputation: 2361

imagesc with multiple axis and ticklines

I have a [12 x 6] matrix A that I represent with imagesc and on which I impose some thick tick-lines:

figure
imagesc(A)

set(gca,'xtick', linspace(0.5,size(A,2)+0.5,C+1),...
     'ytick', linspace(0.5,size(A,1)+0.5,B*al+1),'linewidth',3);
set(gca,'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor',
     'k', 'ycolor', 'k');
set(gca, 'XTickLabelMode', 'manual', 'XTickLabel', [],'YTickLabel', []);
colorbar

A

I then want to impose some thinner tick-lines to split in two each box delimited by the thicker lines:

ax1 = gca;
ax1_pos = get(ax1,'Position'); % position of first axes
ax2 = axes('Position',ax1_pos,...
    'XAxisLocation','top',...
    'YAxisLocation','right',...
    'Color','none');
set(gca,'xtick', linspace(0.5,size(A,2)+0.5,2*C+1),'linewidth',1);

B

The result is clearly not satisfying. How could I fix it? I thought that 'Color','none' would have done the trick...

Upvotes: 1

Views: 341

Answers (1)

gnovice
gnovice

Reputation: 125874

Instead of trying to modify tick lengths and adding a second axes, I would just plot some extra lines on top of your image. This should achieve what you want:

% Some sample data:
A = rand(12, 6);

% Plot image:
imagesc(A);
set(gca, 'Visible', 'off');
hold on;
colorbar;

% Plot horizontal lines:
yLines = repmat((0:size(A, 1))+0.5, 2, 1);
xLines = repmat([0.5; size(A, 2)+0.5], 1, size(yLines, 2));
line(xLines, yLines, 'LineWidth', 3, 'Color', 'k');

% Plot thick vertical lines:
xLines = repmat((0:2:size(A, 2))+0.5, 2, 1);
yLines = repmat([0.5; size(A, 1)+0.5], 1, size(xLines, 2));
line(xLines, yLines, 'LineWidth', 3, 'Color', 'k');

% Plot thin vertical lines:
xLines = repmat((1:2:size(A, 2))+0.5, 2, 1);
yLines = repmat([0.5; size(A, 1)+0.5], 1, size(xLines, 2));
line(xLines, yLines, 'LineWidth', 1, 'Color', 'k');

And here's the plot:

enter image description here

Upvotes: 1

Related Questions