writing all numbers on x axes with plot function

45 次查看(过去 30 天)
%for example
id=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
north=[100;101;102;103;104;105;106;107;108;109;110;111;112;113;114];
figure;
plot(id,north,'b')
title('NORTH-COORDINATE TIME SERIES')
xlabel('SESSIONS')
ylabel('NORTH')
%I want that every number of id appears on the x axes (not, 0-5-10-15) in the figure.

采纳的回答

Star Strider
Star Strider 2014-11-22
Add a command to specify the 'XTick' values to put every value of ‘id’ on the x-axis:
id=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
north=[100;101;102;103;104;105;106;107;108;109;110;111;112;113;114];
figure;
plot(id,north,'b')
title('NORTH-COORDINATE TIME SERIES')
xlabel('SESSIONS')
ylabel('NORTH')
set(gca, 'XTick',id) % Specify XTick Values
  2 个评论
sermet
sermet 2014-11-22
I applied it but sometimes id numbers are quite high like (200-150) then it doesn't seem properly on the x axes in the figure. Is this a way that all numbers are visible even they are too many.
Star Strider
Star Strider 2014-11-22
Probably the easiest way is to reduce the FontSize:
id=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
north=[100;101;102;103;104;105;106;107;108;109;110;111;112;113;114];
figure;
plot(id,north,'b')
title('NORTH-COORDINATE TIME SERIES', 'FontSize',12)
xlabel('SESSIONS', 'FontSize',10)
ylabel('NORTH', 'FontSize',10)
set(gca, 'XTick',id, 'FontSize',7) % Specify XTick Values
This reduces the font size on all axes tick labels and everything else as well, so you have to set the title and axis labels individually, as I did here.
In R2014b, you can easily rotate the tick labels so they won’t overlap. If the tick labels are densely packed, you may want to plot every other one or every fifth one, for instance. If you have R2014a or earlier, you will have to specify the 'XTickLabel' values as a cell array of strings, and rotate them using the Text Properties command functions.
The easiest way to deal with densely packed tick labels is simply to display fewer of them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by