How do I center axis labels in pcolor graph?

25 views (last 30 days)
I have a pcolor "checkerboard plot" , how do I center the axis values to the center of the box (but still on the axis). I am using matlab 2012b.
Heres some code:
figure;
pcolor(1:13,1:5,ones(5,13))
xt = 1:12;
yt = 1:4;
set(gca,'XTick',xt)
set(gca,'YTick',yt)

Accepted Answer

Alok Virkar
Alok Virkar on 16 Nov 2020
setting axis x location to origin didnt work for me.
I changed some code and used imagesc instead of pcolor.
c = zeros(5,5);
c(1,1) = 1;
im = imagesc(c);
ax = gca;
ax.XTick = 1:5;
ax.YTick = 1:5;
ax.YDir = 'normal';
  1 Comment
Douglas Anderson
Douglas Anderson on 13 Sep 2022
I would like to thank you, Alok! I tried using heatmap() for the same kind of problem, and was frustrated at every turn. This ended up as a very simple, elegant solution.

Sign in to comment.

More Answers (1)

Mathieu NOE
Mathieu NOE on 10 Nov 2020
  1 Comment
Alok Virkar
Alok Virkar on 11 Nov 2020
setting axis x location to origin didnt work for me.
I changed some code and used imagesc instead of pcolor.
c = zeros(5,5);
c(1,1) = 1;
im = imagesc(c);
ax = gca;
ax.XTick = 1:5;
ax.YTick = 1:5;
ax.YDir = 'normal';

Sign in to comment.

Categories

Find more on Geographic 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!