Adding and customisng a single tick mark

19 vues (au cours des 30 derniers jours)
Jason
Jason le 21 Mar 2018
Commenté : Jason le 22 Mar 2018
hello.
I want to add a single tick mark to the current tickmarks:
set(gca, 'XTick', sort([0.018, get(gca, 'XTick')]));
But I want its text to be smaller and a different colour to the rest. Is this possible

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Mar 2018
new_tick = 0.018;
new_fontsize = 6;
new_tick_rgb = [0.28, 0.02, 0.03]; %Bulgarian Rose
ax = gca;
xruler = ax.XRuler;
old_fmt = xruler.TickLabelFormat;
old_xticks = xruler.TickValues;
old_labels = sprintfc(old_fmt, old_xticks);
new_label = sprintf(['%s%g,%g,%g%s%d%s' old_fmt], '\color[rgb]{', new_tick_rgb, '}\fontsize{', new_fontsize, '}', new_tick);
all_xticks = [old_xticks, new_tick];
all_xlabels = [old_labels, new_label];
[new_xticks, sort_order] = sort(all_xticks);
new_labels = all_xlabels(sort_order);
set(xruler, 'TickValues', new_xticks, 'TickLabels', new_labels);
  1 commentaire
Jason
Jason le 22 Mar 2018
Perfect, thankyou very much

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by