problem axis "x" in my graph

1 visualización (últimos 30 días)
aldo
aldo el 6 de Nov. de 2023
Comentada: aldo el 7 de Nov. de 2023
size(XDates)
ans =
5 1
size(E)
ans =
5 35
for i=1:c
col=map(i,:);
plot(Ax,XDates,E(:,i),'DisplayName','Equity','Color',col);
if writeText_right
text(Ax,gg,E(end,i),strcat(num2str(fix(E(end,i)/1000)),"k","***",num2str(i),"-",nome(i)),'Color',col,'Interpreter','none');
end
end
In size(XDates) i see 5 element but in the graph there are date pairs
  1 comentario
Star Strider
Star Strider el 6 de Nov. de 2023
The date ticks appear to be separated by 12 hour intervals.

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 6 de Nov. de 2023
It automatically adds x tick labels and sometimes they are not exactly what your x vector was. If you want to specify exactly what they are use xticks and xticklabels.

Steven Lord
Steven Lord el 6 de Nov. de 2023
Those seem reasonable to me. They're showing the month and date along with the time of data for each of your X coordinates. I suspect you've created them in a format that include this information when the datetime array is displayed.
x = datetime(2023, 10, 30):datetime(2023, 11, 03)
x = 1×5 datetime array
30-Oct-2023 31-Oct-2023 01-Nov-2023 02-Nov-2023 03-Nov-2023
x.Format = x.Format + " HH:mm"
x = 1×5 datetime array
30-Oct-2023 00:00 31-Oct-2023 00:00 01-Nov-2023 00:00 02-Nov-2023 00:00 03-Nov-2023 00:00
plot(x, 1:5, 'o-')
If you want to control which ticks are displayed, use the xticks function. If you want to control the formatting of the ticks, use xtickformat. To eliminate the year at the lower-right corner of the axes, if you're using release R2023b or later use the xsecondarylabel function.
figure
plot(x, 1:5, 'o-')
xticks(x([1 3 4 5])) % Skip tick 2
xtickformat('MM/dd@HH:mm')
xsecondarylabel(Visible=false)
If this isn't the problem that you had in mind when you posted your question, please clarify how you'd like the apperance of the figure to be different.
  3 comentarios
Steven Lord
Steven Lord el 6 de Nov. de 2023
i think che problem is : XDates = [datetime(datestr(BackTest_Vect_Inizio:BackTest_Vect_Fine))];
Don't use datestr. You don't need it in this case as the colon operator works just fine for datetime arrays.
T1 = datetime('today')
T1 = datetime
06-Nov-2023
T2 = T1 + days(7) % next Monday, as I'm running this code on a Monday
T2 = datetime
13-Nov-2023
V = (T1:T2).'
V = 8×1 datetime array
06-Nov-2023 07-Nov-2023 08-Nov-2023 09-Nov-2023 10-Nov-2023 11-Nov-2023 12-Nov-2023 13-Nov-2023
but is it possible to have only the date in the dateTime format? (I don't need to use the time)
Sure. The datetime documentation page has a section on the Format property of datetime arrays. If you don't want to include any of the time components in your array's Format property you don't need to include it. Just build the format you want. For example, let's tweak the default display Format for a datetime array that includes both date and time information.
N = datetime('now')
N = datetime
06-Nov-2023 20:31:24
N.Format
ans = 'dd-MMM-uuuu HH:mm:ss'
Let's include the name of the day of the week (eeee), the full name of the month (MMMM), the day of the month (dd), the year (yyyy), the day of the year (D), and some text wrapped in single quotes that datetime will use unchanged in the display (not treating the d in 'day' as "Day of the month, using one or two digits", for example.)
F = "eeee, MMMM dd yyyy, 'day' D 'of the year'"
F = "eeee, MMMM dd yyyy, 'day' D 'of the year'"
N.Format = F
N = datetime
Monday, November 06 2023, day 310 of the year
You may need to call xtickformat with F as input instead of specifying it as the Format of the data you plot.
aldo
aldo el 6 de Nov. de 2023
thank you for explenation

Iniciar sesión para comentar.


aldo
aldo el 6 de Nov. de 2023
Editada: aldo el 7 de Nov. de 2023
but there is still the problem... Leaving aside the writing of the dates on the x axis, I saw that using 1:5 as an interval gives me 10 steps at 0.5 distance
[r,c]=size(E);
map = hsv(c);
map=map(randperm(c),:); %%AGGIUNTO .. cosi' estrae sequenze a caso ed evito di vedere colori simili vicini
hold(Ax, 'on')
for i=1:c
col=map(i,:);
plot(Ax,1:r,E(:,i),'DisplayName','Equity','Color',col);
if writeText_right
text(Ax,gg,E(end,i),strcat(num2str(fix(E(end,i)/1000)),"k","***",num2str(i),"-",nome(i)),'Color',col,'Interpreter','none');
end
end
>>
r
  4 comentarios
aldo
aldo el 7 de Nov. de 2023
but if you want you can help me
aldo
aldo el 7 de Nov. de 2023
i undrestand what is the problem: @Steven Lord
x = datetime(2023, 10, 30):datetime(2023, 11, 03)
x.Format = x.Format + " HH:mm"
plot(x, 1:5, 'o-') (Immagine.png)
but if I enlarge it to full screen I get the x axis intervals doubled (Immagine1.png)

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by