How i can change the x-axis labels and ticks like that
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
samer hisham
am 13 Nov. 2019
Kommentiert: samer hisham
am 16 Nov. 2019
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 Kommentare
Akzeptierte Antwort
Adam Danz
am 13 Nov. 2019
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 Kommentare
Adam Danz
am 13 Nov. 2019
Bearbeitet: Adam Danz
am 15 Nov. 2019
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'})
Weitere Antworten (1)
samer hisham
am 13 Nov. 2019
1 Kommentar
Adam Danz
am 13 Nov. 2019
I replied under my answer. Please use the comment sections for comments and discussion and reserve the answer sections for answers.
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!