Plot with 3 Variables
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a table with 3 variables that I would like to put into a plot. I have variable X that I want on the X-axis, variable Y that I want on the Y-axis, and then a third variable titled 'Activity'. Is it possible to plot the X and Y as normal and add the third variable through color coding with a key? I'm open to other ideas as well! Thanks in advance!
댓글 수: 0
채택된 답변
Star Strider
2021년 7월 5일
If I understand correctly, the scatter function (or a combination of scatter and plot if you want the points connnected with lines) would likely work.
Example —
T1 = array2table([rand(20,2) randi(4, 20, 1)], 'VariableNames',{'X','Y','Activity'})
Ua = unique(T1.Activity);
figure % Specific Number Of Unique 'Activity' Values & Legend Entries
hold on
for k = 1:numel(Ua)
vk = T1.Activity == k;
hs{k} = scatter(T1.X(vk,:), T1.Y(vk,:), 25, T1.Activity(vk,:),'filled');
end
hold off
grid
colormap('turbo')
legend([hs{:}],compose('Activity %d',Ua), 'Location','best')
figure % Any Number Of Activity Values, Optionally Connectyed By Lines, No Specific LEgend
scatter(T1.X, T1.Y, 25, T1.Activity,'filled')
hold on
plot(T1.X, T1.Y, ':k')
hold off
grid
colormap('turbo')
Make appropriate changes to get the result you want
.
댓글 수: 0
추가 답변 (1개)
Image Analyst
2021년 7월 5일
Sure
plot(t.X, t.Y, 'b.-'); % t is your table variable.
Not sure what the third variable is or how you want it to appear on the x-y graph. Please explain and attach your table in a .mat file
save('answers.mat', 'yourTable');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

