Visualy change values of legend
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
As seen I got 288 Values on x and on the x legend it also goes from 0 -300.
I want the x axis to only show me visualy the values from 0-24 without changing any values on the y axis.
Every 12 elements on x it should show me a +1.
Like switching the "Values"
Current What I want
12 1
24 2
36 3
48 4
60 5
72 6
... ...
288 24
Risposte (2)
Star Strider
il 14 Giu 2022
Modificato: Star Strider
il 14 Giu 2022
Possibly —
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
xlim([min(x) max(x)])
Ax = gca;
xt = Ax.XTick;
Ax.XTickLabel = fix(xt*(5/60)); % Scale By 5 min Intervals / 60 minutes
EDIT — (14 Jun 2022 at 13:10)
To get the x-axis ticks to display 12-hour increments as requested, change the XTick increment and the XTickLabel assignment:
x = [1:288*7]; % Increase To 7 Days
y = rand(288*7,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
xlim([min(x) max(x)])
hour12 = 60*12/5; % 12-Hour Increment
Ax = gca;
Ax.XTick = x(1:hour12:end); % X-Tick Values
Ax.XTickLabel = floor(Ax.XTick * 5/(60*12)); % X-Tick Labels
% XTickVals = buffer(Ax.XTick * 5/(60*12),7) % Information
.
2 Commenti
Image Analyst
il 14 Giu 2022
Maybe just divide by 5 before plotting
x = [1:288];
y = rand(288,1);
plot(x/5,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
Steven Lord
il 14 Giu 2022
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
tickLocations = 12:12:288;
xticks(tickLocations)
xticklabels(string(tickLocations/12))
Once you've changed the tick labels your X label is at best misleading, so I'd change that to 'time (hours)' or something similar.
0 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!