Adding a colorbar to parallel coordinate plot
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I am doing a parallel coordinate plot using the "parallelplot" plot command (example shown below). I have a range of 100 values as my "GroupVariable" and rather than have a 100 different categories for my legend, I just want to use a colorbar to show the gradient. I know I can plot in otherways to avoid this issue, but given that parallel coordinate plots can present and highlight data differently based on the arrangement of your factors and grouping strategies, I want to give a colorbar a try since I like this arrangement best for my data. Is there a way to add a colorbar legend easily? The only other option I can think of is doing two subplots, one with the parallel plotting command and another with a simple plotting command that will let me add a colorbar, and then supressing the second subplot and only showing the associated colorbar. But that's a little involved ,so I am hoping for a simpler solution.
Thanks in advanced!
%% generate numbers
a = randi([1,5],100,1);
b = randi([3,9],100,1);
c = randi([10,20],100,1);
d = rand(100,1);
%% make table
labels = {'a', 'b', 'c','d'};
T = table(a,b,c,d,'VariableNames',labels);
coordvars = {'a','b','c'};
%%sort rows for plotting
T_sort = sortrows(T,4);
%% plotting
p = parallelplot(T_sort,'CoordinateVariables',coordvars,'GroupVariable','d','DataNormalization','zscore');
p.Jitter = 0.3;
% assign color
p.Color = autumn;
%%%%%%%%%%% insert colorbar legend somehow instead of 100 different categories?? %%%%%%%%%%%%%
0 commentaires
Réponse acceptée
Chunru
le 27 Août 2021
You can try to put a color bar in a subplot.
a = randi([1,5],100,1);
b = randi([3,9],100,1);
c = randi([10,20],100,1);
d = rand(100,1);
%% make table
labels = {'a', 'b', 'c','d'};
T = table(a,b,c,d,'VariableNames',labels);
coordvars = {'a','b','c'};
%%sort rows for plotting
T_sort = sortrows(T,4);
%% plotting
subplot(1,8, [1:7])
p = parallelplot(T_sort,'CoordinateVariables',coordvars,'GroupVariable','d','DataNormalization','zscore');
p.Jitter = 0.3;
% assign color
p.Color = hsv;
p.LegendVisible = 'off';
subplot(1,8,8);
ncolors = size(p.Color, 1);
image(1, 1:ncolors, (1:ncolors)'); axis xy
colormap(p.Color);
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!