Giving different colors in skyplot when default colors repeat
9 views (last 30 days)
Show older comments
Hi all,
I was trying to get a skyplot for 15 different satellites but it seems that the colors in the legend is repeating. I actually wanted to give unique colors for the individual satellites, and tried the following:
initialColorOrder = get(gca,'ColorOrder') % to display the initial colors
newDefaultColors = copper(15)
set(gca, 'ColorOrder', newDefaultColors, 'NextPlot', 'replacechildren')
newColorOrder = get(gca,'ColorOrder') % to display the new colors
skyplot(azimuth, elevation, GroupData=categorical(g))
legend()
Even though I could see that newColorOrder now contains 15 different colors its not reflected in the skyplot which still is using the initial default colors. Any suggestion why that is happening?
I also tried the following:
skyplot(azimuth, elevation, GroupData=categorical(g))
legend()
colororder(parula(15))
Even though it appears to give what I desired, the individual colors are most of the times indistinguishable ''visually''.
Thanks
0 Comments
Accepted Answer
Voss
on 22 Apr 2022
Edited: Voss
on 22 Apr 2022
When you set the ColorOrder of gca before calling skyplot, you are setting properties of the current axes, whatever it is. Then skyplot makes a new axes, so whatever you did to the old current axes is irrelevant for skyplot.
When you set the ColorOrder of gca after calling skyplot, then the current axes is the axes that skyplot created, so it works.
Now you just have to change parula(15) to a set of colors you prefer.
azimuth = 360*rand(1,15);
elevation = 90*rand(1,15);
g = rand(1,15);
skyplot(azimuth, elevation, GroupData=categorical(g))
legend()
colororder(turbo(15))
9 Comments
Voss
on 22 Apr 2022
n_sat = 15; % number of satellites
n_pts = 5; % number of points per satellite
% trying to make some random yet coherent tracks for the satellites here
% (obviously you can just use your azimuth and elevation data)
azimuth = mod(cumsum([360*rand(1,n_sat); 5*rand(n_pts-1,n_sat)],1),360);
elevation = mod(cumsum([90*rand(1,n_sat); 10*rand(n_pts-1,n_sat)],1),90);
% repeat the same groups 1-15 for all n_pts points
g = categorical(repmat(1:n_sat,n_pts,1));
% construct labels
prn = repmat({''},n_pts,n_sat);
% only first row is non-empty
prn(1,:) = sprintfc('Sat. %d',1:n_sat);
% construct marker sizes
ms = 10*ones(n_pts,n_sat);
% make markers for satellite 1 larger than the others:
ms(:,1) = 50;
skyplot(azimuth(:), elevation(:), prn(:), MarkerSize=ms(:), LabelFontSize=12, GroupData=g(:))
% legend() % don't need the legend if you have labels
colororder(turbo(n_sat))
Note that MarkerSize is a vector with one element per data point, so you can have them vary however you want:
% construct marker sizes
ms = (90-elevation).^1.5.*abs(cosd(azimuth));
skyplot(azimuth(:), elevation(:), prn(:), MarkerSize=ms(:), LabelFontSize=12, GroupData=g(:))
% legend() % don't need the legend if you have labels
colororder(turbo(n_sat))
More Answers (1)
See Also
Categories
Find more on Reference Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!