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!

