Axis Ticks using Calendar Year ticks with BC years

1 次查看(过去 30 天)
I have some code here used for Grain Size analysis of a core, I wanted to correlate each point with an age, so I created a list with age of each with years and formatted them to use the 'yyyy G' format. however when I try to use the yticks command to create certain tick labels, it says that it cannot use the list since it is not "increasing" due to how the ISO labelling system works for years. is there a way to make this work? Code without and with system is below.
cla reset
plot(GSListNorm,DepthList)
set(gca,'YDir','reverse')
yyaxis left
xline(median(GSListNorm),"--r")
xlabel(["Normalized Grain Size at 90%"])
ylabel(["Depth";"(cm)"])
xlim([-2 5])
ylim([0 110])
yticks(0:10:max(DepthList))
yyaxis right
plot(GSListNorm,YearAge,LineStyle='none')
ylabel(["Age","Calendar Year"])
ytickformat('yyyy G')
saveas(gcf,'GSNoTrend','png')
cla reset
YearTicks = datetime('1950' '1725' '1501' '1277' '1053' '0828' '0604' '0380' '0156' '0069' '0293')% I know this code isn't right but these are the values of the list
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
cla reset
plot(GSListNorm,DepthList)
set(gca,'YDir','reverse')
yyaxis left
xline(median(GSListNorm),"--r")
xlabel(["Normalized Grain Size at 90%"])
ylabel(["Depth";"(cm)"])
xlim([-2 5])
ylim([0 110])
yticks(0:10:max(DepthList))
yyaxis right
plot(GSListNorm,YearAge,LineStyle='none')
ylabel(["Age","Calendar Year"])
ytickformat('yyyy G')
yticks(YearTicks)
saveas(gcf,'GSNoTrend','png')
cla reset
Error using yticks
Tick values must be a vector of increasing datetime values.

采纳的回答

Walter Roberson
Walter Roberson 2023-1-23
移动:Walter Roberson 2023-1-23
YearTicks = datetime({'1950 CE'; '1725 CE'; '1501 CE'; '1277 CE'; '1053 CE'; '0828 CE'; '0604 CE'; '0380 CE'; '0156 CE'; '0069 CE'; '0293 BCE'}, 'Inputformat', 'yyyy G', 'Format', 'yyyy G');
plot(rand(1,length(YearTicks)), YearTicks)
yticks( sort(YearTicks))
  2 个评论
Charles Mina
Charles Mina 2023-1-24
Thank You! but i would like to ask why the sort is necessary?
Walter Roberson
Walter Roberson 2023-1-24
yticks() requires that the values be given in increasing order, but your input YearTicks are in decreasing order.
You could also have done
yticks( flipud(YearTicks) )
but that is fragile against the possibility that YearTicks is already increasing, or against the possibility that YearTicks is a row vector instead of a column vector.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by