problem axis "x" in my graph
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (3)
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.
0 comentarios
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.Format = x.Format + " HH:mm"
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
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')
T2 = T1 + days(7) % next Monday, as I'm running this code on a Monday
V = (T1:T2).'
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.Format
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'"
N.Format = F
You may need to call xtickformat with F as input instead of specifying it as the Format of the data you plot.
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!