MATLAB Answers

histogram style graph with several different data types with each type coloured differently

조회 수: 17(최근 30일)
Oliver Nicholls
Oliver Nicholls 10 Apr 2021 11:13
댓글: Oliver Nicholls 11 Apr 2021 7:13
I have a bunch of papers using different calculaton methords. I want to graph along the x axis the year the paper was published and on the y have boxes sized corrasponding to the number of papers of a given type published in that year where each type is coloured seperatly like a stacked bar chart. I have tried all manour of things and the closest thing I have got is this using a stacked bar chart but this is basically roated 90degrees from what I want (year on the x and number on the y with coloured boxes indicating type:

채택된 답변

dpb
dpb 10 Apr 2021 16:02
Actually, it's not too bad to just make up something...not sure where and why you ran into difficulties without seeing what sort of things you did try, but--
METHODS=categorical(string(('A':'E').')); % easier than typing in your categories
YEARS=[2001:2010].'; % arbitrary years
n=randi(300,numel(YEARS),numel(METHODS)); % generate some numbers by year and method
hB=bar(YEARS,n.','stacked'); % put on stacked bar by year
xlim(xlim+[1 -1]*0.6) % I think extra white space at ends is ugly...
legend(METHODS) % add legend and labels
xlabel('Publication Year'),ylabel('Number Publications by Method')
resulted in

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by