Plot with 3 Variables
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Gillian Murray
il 5 Lug 2021
Risposto: Star Strider
il 5 Lug 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 Commenti
Risposta accettata
Star Strider
il 5 Lug 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 Commenti
Più risposte (1)
Image Analyst
il 5 Lug 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 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

