How can I specify axis spacing?

Hey Guys,
I am plotting a figure that x takes values of [4 8 16 32 64 128 256 512 1024]. I use
%%
x = [4 8 16 32 64 128 256 512 1024];
plot(x, Y)
set(gca,'XTick',x)
The problem is the x-axis = [4 8 16 32 ] overlap and it's not readable. How can I fixed that? Many thanks in advance!untitled.jpg

2 Comments

Use a logarithmic scale. Then the ticks are equi-distant.
Thank you so much! Could you please take a look at the following comment and let me know if you have any sugesstions? Thanks in advance!

Sign in to comment.

 Accepted Answer

One option:
x = [4 8 16 32 64 128 256 512 1024];
plot(log2(x), Y)
set(gca,'XTick',log2(x), 'XTickLabel',x)
It would be a bit easier if we knew ‘Y’, and what you wnat it to look like.

4 Comments

Thank you so much for your reply. It was very helpful.
However, it gave me the same distance between 4-8 and between 512-1024. I was wondering if it is possible to have the same scale as it given in the above figure (, i.e., the distance between 512-1024 is twice of the distance between 256-512 and so on) with readable x values from 4 to 64? Any idea would be greatly appreciated.
This is the Y values (each row for each curve)
%%
0.0752 0.1186 0.1696 0.2301 0.2958 0.3550 0.3986 0.4259 0.4414
0.0805 0.1294 0.1897 0.2651 0.3526 0.4365 0.5016 0.5440 0.5686
0.0735 0.1208 0.1819 0.2632 0.3648 0.4706 0.5587 0.6193 0.6556
0.0595 0.0999 0.1546 0.2325 0.3387 0.4609 0.5732 0.6567 0.7094
0.0424 0.0726 0.1154 0.1805 0.2780 0.4047 0.5375 0.6482 0.7244
0.0267 0.0464 0.0755 0.1222 0.1985 0.3109 0.4486 0.5829 0.6879
0.0153 0.0268 0.0443 0.0735 0.1246 0.2083 0.3274 0.4660 0.5942
0.0082 0.0145 0.0242 0.0408 0.0711 0.1246 0.2103 0.3273 0.4568
0.0043 0.0076 0.0127 0.0216 0.0382 0.0689 0.1222 0.2040 0.3098
As always, my pleasure.
Try this:
x = [4 8 16 32 64 128 256 512 1024];
Y = [ 0.0752 0.1186 0.1696 0.2301 0.2958 0.3550 0.3986 0.4259 0.4414
0.0805 0.1294 0.1897 0.2651 0.3526 0.4365 0.5016 0.5440 0.5686
0.0735 0.1208 0.1819 0.2632 0.3648 0.4706 0.5587 0.6193 0.6556
0.0595 0.0999 0.1546 0.2325 0.3387 0.4609 0.5732 0.6567 0.7094
0.0424 0.0726 0.1154 0.1805 0.2780 0.4047 0.5375 0.6482 0.7244
0.0267 0.0464 0.0755 0.1222 0.1985 0.3109 0.4486 0.5829 0.6879
0.0153 0.0268 0.0443 0.0735 0.1246 0.2083 0.3274 0.4660 0.5942
0.0082 0.0145 0.0242 0.0408 0.0711 0.1246 0.2103 0.3273 0.4568
0.0043 0.0076 0.0127 0.0216 0.0382 0.0689 0.1222 0.2040 0.3098];
xv = [linspace(x(1),x(6),6)*1.5 (x(7:end))]; % X-Vector
plot(xv, Y)
set(gca,'XTick',xv, 'XTickLabel',x, 'FontSize',8)
xlim([min(x) max(x)])
producing:
It linearly spaces the values below 128, then uses the natural spacing for numbers above that. That is the only way I can think of to meet your readability and spacing needs.
Thank you SO much!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Asked:

on 12 Jun 2019

Commented:

on 12 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!