Borrar filtros
Borrar filtros

Bar graphing extra categorical info

3 visualizaciones (últimos 30 días)
Calvin Ebert
Calvin Ebert el 26 de Mzo. de 2019
Comentada: dpb el 28 de Mzo. de 2019
I am trying to plot a bar graph of the "worst 5" of something. I am revamping some code from before. Before, I used c=categorical(names of things) then c(Position of worst 5) to graph and it worked. It showed only the 5 from the list. I am trying the same thing again, but it keeps showing the whole list. I have tried setting D=c(Bad Pos) and using that in bar, I have tried clearing the c variable while doing that as well. No matter what, it keeps graphing everything.
WHY=c(BadPosW,1);
WorstSpeeds=Speedsa(BadPosW,:)
figure(1)
subplot(2,2,2)
Worst5Plot=bar(WHY, [WorstSpeeds(1:5,4) WorstSpeeds(1:5,5) WorstSpeeds(1:5,6)])
As of right now, thats the last thing I have tried.
bar(WHY, [WorstSpeeds(:,4) WorstSpeeds(:,5) WorstSpeeds(:,6)])
Above is what I am entering and is still giving extra data. I saved the original c, the cut c as WHY and the speeds. I tried loading only WHY and WorstSpeeds, still giving me all the other data somehow.
  2 comentarios
dpb
dpb el 26 de Mzo. de 2019
We'd have to see a minimum working example including data to be able to diagnose the issue.
Calvin Ebert
Calvin Ebert el 27 de Mzo. de 2019
I have updated with the variables from the workspace

Iniciar sesión para comentar.

Respuesta aceptada

Calvin Ebert
Calvin Ebert el 27 de Mzo. de 2019
did WHY=string(WHY)
then WHY=categorical(WHY) and it worked. Still dont understand what was going on to cause it to pull all the values and would be curious if anyone has an explanation but that solved it.
  4 comentarios
dpb
dpb el 27 de Mzo. de 2019
Editada: dpb el 28 de Mzo. de 2019
Sure, except it really wouldn't be two lines but a built string...another Answer illustrated this just a day or so ago for a text object but the same "trick" works for tick labels...
Of course, you quickly run out of room on axes...
NB: you can, of course, also build those text strings dynamically an example of which was in last comment at
That was in a loop for "one-at-a-time" but for tick labels it's more handy to use the vectorized ability of num2str instead...one caveat there is you must use a column vector for the input arrays or the output cell strings will be run together horizontally.
dpb
dpb el 28 de Mzo. de 2019
I did submit a SRQ for consideration of ths behavior in the categorical axis object. PLOT() behaves identically, not surprisingly.
We'll see what TMW has to say... :)

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 28 de Mzo. de 2019
Try just calling histogram. First let's build some categorical data:
C = ["apple"; "banana"; "cherry"; "strawberry"; "kiwi"; "watermelon"];
V = randi(numel(C), 1000, 1);
catData = categorical(C(V));
Next let's show the histogram containing all the data.
figure;
h = histogram(catData);
Finally let's show just the three largest bins.
figure
h = histogram(catData, 'NumDisplayBins', 3, 'DisplayOrder', 'descend');
There are other options that may be of use to you, like 'ShowOthers' if you want to see one catch-all bin for everything that's not in the top 'NumDisplayBins' bins or if you already have the 'BinCounts' and want to specify those as the values to use when creating the bars for the 'Categories'. See the documentation for histogram for more information on the options to which I referred.
  1 comentario
dpb
dpb el 28 de Mzo. de 2019
That's kewl and some new features in histogram I wasn't aware of, Steven.
I think the issue w/ bar and plot is still real, however, as (at least OTOMH) I don't see how to build the grouped bar plot with histogram as his data are 2D, not just a vector.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by