Adding a colorbar to parallel coordinate plot
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chunru
2021-8-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!