Axis Ticks using Calendar Year ticks with BC years

1 回表示 (過去 30 日間)
Charles Mina
Charles Mina 2023 年 1 月 23 日
コメント済み: Walter Roberson 2023 年 1 月 24 日
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 Center および File ExchangeCalendar についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by