5

I have a figure and I'd like to be able to show the ticks positions (in white) but keep the tick labels (in black). For example, if you try:

imagesc(abs(peaks(10))); colormap('bone');
set(gca,'XTick',0:pi:2*pi,'XTickLabel',{'0', 'p', '2p'},'fontname','symbol');

enter image description here

You can see that the tick positions can't be seen. Matlab's documentation tells that the handle YColor and XColor can be used, but they also control the color of the tick labels. For example: enter image description here

I have tried to get the tick out, but it doesn't look good. I tried playing with an approach similar to the one discussed here, but without success. The last way I can think of is to "manually" rewrite the labels as text objects... Would appreciate your input.

Community
  • 1
  • 1
bla
  • 25,846
  • 10
  • 70
  • 101
  • 1
    [This idea](http://stackoverflow.com/a/10235518/2586922) might be useful – Luis Mendo Apr 02 '14 at 23:18
  • You can now do this using the [undocumented axis rulers](http://undocumentedmatlab.com/blog/customizing-axes-rulers). – Dan Jan 22 '16 at 14:16
  • good to know! (I just needed that yesterday again :) ) you can add it as an answer. – bla Jan 22 '16 at 17:32

1 Answers1

6

Since there are no independent attributes for the ticks, only tailor-made tricks spring to mind.

The result of this

imagesc(abs(peaks(10)));
colormap('bone');
set(gca, 'XTick', 0:pi:2*pi, 'XTickLabel', {'0', 'p', '2p'}, 'fontname','symbol');
a = gca;
b = copyobj(a, gcf)
set(b, 'Xcolor', [1 1 1], 'YColor', [1 1 1], 'XTickLabel', [], 'YTickLabel', [])

is this

Clone axes and modify attributes

Drake
  • 857
  • 5
  • 10
  • thanks for the answer. The problem I still have is that I also control the positions and labels of the ticks, so using your code overwrite the ticks in other places. (see my edited question)... – bla Apr 03 '14 at 00:16
  • thanks Drake, this works, and the only thing to add is that the user needs to add the `xlabel` and `ylabel` after this code to get them look ok, otherwise they are get sketchy. – bla Apr 03 '14 at 05:41
  • 2
    +1, nice! I would also add a `linkaxes([a b])` so that zooming and panning doesn't mess up the axes. – Rody Oldenhuis Apr 03 '14 at 05:42
  • @RodyOldenhuis Good point, hence +1. "@"natan You are welcome. – Drake Apr 03 '14 at 08:08