필터 지우기
필터 지우기

Data visualization using a matlab figure/graph

조회 수: 2 (최근 30일)
Julian
Julian 2019년 9월 5일
댓글: Julian 2019년 9월 8일
Hi everyone,
im struggling with visualizing my data in a matlab figure.
Imagin i'm having three collumns.
  1. Label (Label 1, Label 2, Label 3)
  2. Attribute (A1, A2, A3, A4)
  3. Number of Observations
Label 1 A1 3
Label 1 A2 6
Label 2 A2 4
Label 2 A3 8
Label 3 A1 9
Now I want to make a graph out of this where I have the labels on the x-axis, the number of observations on the y-axis. Then in the graph it should be seen how often each attribute was oberserved for each attibute. And then the attributes should be stacked onto each other (differentiated by colour).
I can do this in Excel (see attached image), but I was wondering whether this kind ob visualization is also possible in MATLAB.
example.PNG
Thank you so much in advance.
Julian

채택된 답변

Arturo Mendoza Quispe
Arturo Mendoza Quispe 2019년 9월 8일
If you organize your data as :
% A1 A2 A3 A4
X = [ 3, 7, 0, 0; % Label 1
3, 20, 7, 0; % Label 2
3, 4, 0, 8]; % Label 3
You just need:
bar(X, 'stacked');
If you wish to make it look similar to your example:
labels = {'Label 1', 'Label 2', 'Label 3'};
attributes = {'A1', 'A2', 'A3', 'A4'};
figure;
bar(X, 'stacked');
set(gca,'XTickLabel', labels);
set(gca, 'YGrid', 'on', 'XGrid', 'off');
legend(attributes, 'Location', 'NorthOutside', 'Orientation', 'Horizotnal');
colormap([68 114 196;165 165 165;91 155 213;38 68 120] / 255);
ylim([0, 35]);
title('XX');
Furthermore, assuming the data is stored in three variables (i.e., the columns)
Label = {'Label 1', 'Label 1', 'Label 2', 'Label 2', 'Label 3'};
Attribute = {'A1', 'A2', 'A2', 'A3', 'A1'};
Observations = [3, 6, 4, 8, 9];
The "organization" of the data can be done with
labels = {'Label 1', 'Label 2', 'Label 3'};
attributes = {'A1', 'A2', 'A3', 'A4'};
X = zeros(numel(labels), numel(attributes));
for k = 1:numel(Observations)
i = ismember(labels, Label{k});
j = ismember(attributes, Attribute{k});
X(i, j) = X(i, j) + Observations(k);
end
  댓글 수: 1
Julian
Julian 2019년 9월 8일
Thank you very much, I will let you know if it worked as soon as I can :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by