Axis Ticks using Calendar Year ticks with BC years

3 vues (au cours des 30 derniers jours)
Charles Mina
Charles Mina le 23 Jan 2023
Commenté : Walter Roberson le 24 Jan 2023
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Jan 2023
Déplacé(e) : Walter Roberson le 23 Jan 2023
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 commentaires
Charles Mina
Charles Mina le 24 Jan 2023
Thank You! but i would like to ask why the sort is necessary?
Walter Roberson
Walter Roberson le 24 Jan 2023
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by