timbjörn
timbjörn

Reputation: 39

Keep XTick but write out XTickLabel only in loglog plot

I have a plot in loglog system with xlim([15 350]). I want to keep all XTick lines for the grid, but write only the following values on the label: x=20,50,80,100,200.

I've tried set(gca,'XTick',[20,50,80,100,200]), then the intermediate ticks (and so the grid-lines) are removed. Using set(gca,'XTickLabel',[20,50,80,100,200]) doesn't work either. (I've seen an example where two Xtick series are defined, labeled separately, then merged, but couldn't get working for my case, not even sure if possible.)

Would be grateful for some solutions here, this simple thing has been driving me crazy! :)

Thanks! also tried something like removing all XtickLabels, create a new

Upvotes: 2

Views: 1304

Answers (1)

Simon
Simon

Reputation: 32943

First, set your ticks to where you want them, including minor ticks. Then use a cell array containing a value for major ticks and an empty array for minor ticks:

set(gca, 'XTick', [10:10:90, 100:100:400]);
set(gca, 'XTickLabel', {[], 20, [], [], 50, [], [], 80, [], 100, 200});

Upvotes: 1

Related Questions