Borrar filtros
Borrar filtros

How to show all xtick labels in a barplot?

91 visualizaciones (últimos 30 días)
VS
VS el 31 de Mzo. de 2022
Comentada: Star Strider el 31 de Mzo. de 2022
I have a .csv file that contains some ratios for all the US states. I am trying to make a barplot using these ratios (which means 51 bars). I want the names of all territories as tick labels on the x-axis. But I could not make it work Here is what I have done so far:
mydata = readtable('bardata.csv');
mydata_sorted = sortrows(mydata, 4);
bar(mydata_sorted{:,4}); xticklabels(mydata_sorted{:,1});
xtickangle(90);
Will appreciate any help.

Respuesta aceptada

Star Strider
Star Strider el 31 de Mzo. de 2022
Try this —
mydata = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/948329/bardata.csv');
mydata_sorted = sortrows(mydata, 4);
bar(mydata_sorted{:,4});
set(gca,'XTick',1:numel(mydata_sorted{:,1}), 'XTickLabel',mydata_sorted{:,1})
xtickangle(90);
It might be necessary to use the 'Position' property to estend the plot width to make the tick labels less crowded.
.
  2 comentarios
VS
VS el 31 de Mzo. de 2022
Thanks, it worked.
Star Strider
Star Strider el 31 de Mzo. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by