Bar with descending data

1 visualización (últimos 30 días)
Rachele Franceschini
Rachele Franceschini el 21 de Oct. de 2021
Respondida: Cris LaPierre el 22 de Oct. de 2021
I have this bar. But I would like the data in descending order.
How can I do? Help me!
This is "my" script
data100 = readtable(filename100,'TextType','string');
% taking first 10 words.
data100 = data100 (1:10,:);
data100.Word = categorical (data100.Word);
%figure with italian words
figure
bar(data100.Word, data100.Count);
xlabel("Word");
ylabel("Class Distribution");

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 22 de Oct. de 2021
Because your data is categorical, it is getting plotted in alphabetical order by default. You can change the order using reordercats (see this answer).
You can maybe do this programmatically doing something like this (untested):
[~,idx] = sort(data100.Count,'descend');
C = categories(data100.Word);
data100.Word = reordercats(data100.Word,C(idx));

Más respuestas (0)

Categorías

Más información sobre Categorical Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by