Plot with 3 Variables
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gillian Murray
am 5 Jul. 2021
Beantwortet: Star Strider
am 5 Jul. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 5 Jul. 2021
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 Kommentare
Weitere Antworten (1)
Image Analyst
am 5 Jul. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

