How to display a few xticklabels from a set of selected xticks?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
How to display a few xticklabels, like [4, 53] in the following example, from a set of selected xticks?
selected_ticks = [2 3 4 5 6 8 11 1 19 29 53 119];
sorted_selected_ticks = sort(selected_ticks);
plot(1:120,1:120)
xticks(sorted_selected_ticks)
Indeed, just by adding xticklabels([4 53]) after xticks(sorted_selected_ticks) I do not get what expected, i.e. tick lables in position 4 and position 53, and labelled as 4 and 53, respectively, as in the following figure (which is my desired output):
0 comentarios
Respuesta aceptada
Voss
el 31 de Oct. de 2023
selected_ticks = [2 3 4 5 6 8 11 1 19 29 53 119];
selected_labels = [4 53];
sorted_selected_ticks = sort(selected_ticks);
sorted_selected_labels = sort(selected_labels);
[ism,idx] = ismember(sorted_selected_labels,sorted_selected_ticks);
assert(all(ism))
xlabels = strings(1,numel(sorted_selected_ticks));
xlabels(idx) = string(sorted_selected_labels);
plot(1:120,1:120)
xticks(sorted_selected_ticks)
xticklabels(xlabels)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!