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
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.
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!