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

3 views (last 30 days)
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:

Accepted Answer

dpb
dpb on 10 Apr 2021
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

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!