3

I want to put labels between ticks, otherwise some labels overlap each other.

set(gca,'XTick',[66 98 134 215 266 330 334 388 414 443 ]);
set(gca,'XTickLabel',{'CD', 'CS', 'E' ,'F','H','I','C','IT','M','U'})

enter image description here

Could somebody please help me?

Adriaan
  • 17,741
  • 7
  • 42
  • 75

2 Answers2

0
xTICKS = [66 98 134 215 266 330 334 388 414 443 ];
xTICKS = [0 xTICKS]; %// Add the 0 instance
dxT = diff(xTICKS);%// get differences
xT = xTICKS(1:end-1)+dxT/2; %// Make new tick locations midway the old

This way you can create the locations of your tickmarks + ticklabels midway the old instances. I'm not sure whether you can uncouple the two though, try this:

set(gca,'XTick',xT);
set(gca,'XTickLabel',{'CD', 'CS', 'E' ,'F','H','I','C','IT','M','U'})

You can play around with axes properties, especially those in the section tick values and labels, but I can't see a way to uncouple the tick location and it's corresponding label.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • Thanks, but this method changes the tick location, too. – user5254599 Nov 06 '15 at 15:58
  • @user5254599 yes, that is exactly what I said *I can't see a way to uncouple the tick location and it's corresponding label* meaning, I do not think there is a way to do this, other than what I showed. I'll check whether it's possible to plot "two axes", one with labels and no ticks and one with ticks and no labels, but I do not have high hopes for that. – Adriaan Nov 06 '15 at 19:44
0

I have run into this problem frequently, but there is a very simple solution...simply pad your labels with spaces on the front! Not necessarily all of them...just the ones that need to move. This is a great trick any time you need a minor adjustment in a text annotation (like with 'arrow', 'text', etc.)

Example:

set(gca,'XTickLabel',{'CD', 'CS', 'E' ,'F','H','I','  C','IT','M','U'})

EDIT: I realized this doesn't address the vertical tick problem. For the Y axis, try

set(gca,'YTickLabel',{'CD', 'CS', 'E' ,'F','H','I',['A' char(10) ' C'],'IT','M','U'})

Note that 'A' and 'C' are technically part of the same label, but they appear to be two different labels because of inserting a line feed (char(10)).

gariepy
  • 3,576
  • 6
  • 21
  • 34