If you want all of the image data to be displayed with pcolor
, you need to pad the input with an extra row and column prior to printing since underneath, pcolor
is a surf
object and the colors are assigned to the vertices not the faces.
jj = [0,1,0;1,0,1;1,1,0];
% Add an extra column
jj(:,end+1) = 0;
% Add an extra row
jj(end+1,:) = 0;
p = pcolor(jj);
Now if you want only the integer labels on the axes, you can tweak them using the XTick
/Ytick
and XTickLabel
/YTickLabel
properties of the axes
to draw the proper values for each element
xlims = get(gca, 'XLim');
ylims = get(gca, 'YLim');
% Must offset ticks by 0.5 to center them
xticks = (xlims(1) + 0.5):(xlims(2) - 0.5);
yticks = (ylims(1) + 0.5):(ylims(2) - 0.5);
xticklabels = arrayfun(@num2str, 1:numel(xticks), 'UniformOutput', 0);
yticklabels = arrayfun(@num2str, 1:numel(yticks), 'UniformOutput', 0);
set(gca, 'xtick', xticks, 'ytick', yticks, ...
'xticklabel', xticklabels, 'yticklabel', yticklabels)
If you don't need the black edges, you can accomplish the same 2D plot by just using imagesc
imagesc(jj);
xlims = get(gca, 'xlim');
ylims = get(gca, 'ylim');
set(gca, 'xtick', xlims(1):xlims(2), 'ytick', ylims(1):ylims(2))