Bar graphing extra categorical info
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
dpb
2019 年 3 月 26 日
We'd have to see a minimum working example including data to be able to diagnose the issue.
採用された回答
Calvin Ebert
2019 年 3 月 27 日
4 件のコメント
dpb
2019 年 3 月 27 日
編集済み: dpb
2019 年 3 月 28 日
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
2019 年 3 月 28 日
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... :)
その他の回答 (1 件)
Steven Lord
2019 年 3 月 28 日
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 件のコメント
dpb
2019 年 3 月 28 日
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.
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!