How i can change the x-axis labels and ticks like that
4 次查看(过去 30 天)
显示 更早的评论
Hello , i have been trying to change my code to get the xticks and xlabels in this image but i dont know what to do
Here is the picture
and here is my picture with the code below it
clc
clear all
close all
dataset = xlsread('Final2.xlsx','Sheet1','C1:D121')
hour = dataset(:,1)
kp = [dataset(:,2)]
t=linspace(0,24,120)
subplot(5,1,1)
bar(hour,kp)
ylabel 'kp index'
grid on
xticks ([0:4:120])
xticklabels({'4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24'})
data = xlsread('Final2.xlsx','Sheet2','D2:I7201')
mins = data(:,1)
Bz = data(:,2)
subplot(5,1,2)
plot(mins,Bz)
%xticks ([s])
%xticklabels({'4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24'})
ylabel 'Bz(nT)'
Vx= data(:,3)
subplot(5,1,3)
plot(mins,Vx)
ylabel 'Vx Km\s'
Al = data(:,4)
Au = data(:,5)
subplot(5,1,4)
hold on
plot(mins,Au)
plot(mins,Al)
ylabel 'AU & AL(nT)'
SYM = data(:,6)
subplot(5,1,5)
plot(mins,SYM)
ylabel 'SYM-H(nT)'
xlabel 'UT(hr)'
%xticks(0:4:120)
%xticklabels({'4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24','4','8','12','16','20','24'})
how i can change the xlabels and xticks to be '0','4','8','12','16','20','24' and repeat itself
0 个评论
采纳的回答
Adam Danz
2019-11-13
If you're using Matlab r2019b or later, you can use tiledlayout() to create your subplots (see examples in that link).
For earlier releases, you can use linkaxes() to set equal axis limits between all subplots. You'll need the axis handles which would look something like this
sbp(1) = subplot(5,1,1);
% Your code
sbp(2) = subplot(5,1,2);
% Your code
sbp(3) = subplot(5,1,3);
% Your code etc.....
% Then, after all subplots are created,
linkaxes(sbp, 'x')
4 个评论
Adam Danz
2019-11-13
编辑:Adam Danz
2019-11-15
Those are 3 different options or ideas, not 3 steps.
I actually don't recommend option 3. Options 1 and 2 are much cleaner and easier.
Here's an example of option 3. The x axis values are actually 1,2,3,4,5 but I've altering their labels to appear as 10,20,30,40,50. If you add a new value at x=40, you won't see it because it will be way off the figure.
figure()
x = [1 2 3 4 5];
y = [1 3 14 29 48];
plot(x,y, 'o')
set(gca, 'XTick', 1:5, 'XTickLabel', {'10' '20' '30' '40' '50'})
更多回答(1 个)
samer hisham
2019-11-13
1 个评论
Adam Danz
2019-11-13
I replied under my answer. Please use the comment sections for comments and discussion and reserve the answer sections for answers.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!