Visualy change values of legend

3 visualizaciones (últimos 30 días)
Eren Atar
Eren Atar el 14 de Jun. de 2022
Respondida: Steven Lord el 14 de Jun. de 2022
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

Respuestas (2)

Star Strider
Star Strider el 14 de Jun. de 2022
Editada: Star Strider el 14 de Jun. de 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 comentarios
Eren Atar
Eren Atar el 14 de Jun. de 2022
I wanted to show every hour sorry for the misunderstandung 12*5min=1hour
Sorry I confused myself...
So I would need the 12. value of the x axis to be 1.
The 24 to be 2 and so on....
Image Analyst
Image Analyst el 14 de Jun. de 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')

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 14 de Jun. de 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.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by