Pugl
Pugl

Reputation: 452

Changing x-axis range in MATLAB without including ticks

Two of my data points are barely visible:

enter image description here

based on this code:

x = 1:8;
y = [70 74 77 78 80 80 82 83];
err = [14 11 12 10 10 7 7 5];
errorbar(x,y,err,'red')
ylabel('Classification results','fontsize',20);
xlabel('Nr of features used', 'fontsize',20);
title('Feature selection with Genetic Algorithm','fontsize',24)
ylim([55 100])

Upvotes: 1

Views: 240

Answers (1)

rayryeng
rayryeng

Reputation: 104503

Simply use xlim and permute the beginning and end ranges by a slight amount... say 0.2:

xlim([min(x) - 0.2, max(x) + 0.2]);

I use min and max here to make it adaptive so that the smallest x value displayed is the smallest one in x subtracted by a 0.2 buffer. Similar logic is applied for the largest x value where the value displayed is the largest one with a 0.2 buffer added.

I now get:

enter image description here

Upvotes: 3

Related Questions