Stackedplot of a multi-column tametable: how to plot each line with a different color
5 views (last 30 days)
Show older comments
Corymbiamaculata
on 25 Feb 2019
Commented: Corymbiamaculata
on 1 Mar 2019
I have a timetable with multi-column variables (12 variables in each column). When using stackedplot, all variables from a given multi-column are plotted with the same colour. Is there any way to change that? I created a custom 12x3 color matrix - this doesn't work as...
Color value must be a 3 element vector
I then tried creating a 1:12 loop with 'hold on', but...
Using hold with stackedplot is not supported.
Is there any way to change that or should I simply use the good old plot function?
0 Comments
Accepted Answer
Geoff Hayes
on 26 Feb 2019
You may be able to change the colours of each line after you have called stackedplot. For example, you might (and I say might because my version of MATLAB doesn't support this function) be able to do the following
myColours = ...; % this is your 12x3 matrix of colours (one for each line)
s = stackedplot(...); % passing in your timetable data; s is a handle to the stacked plot
for k = 1:length(s.LineProperties)
if k <= size(myColours,1)
s.LineProperties(k).Color = myColours(k,:);
end
end
The above assumes that you can iterate over each plot object and change its colour...which the documentation seems to suggest that you can do. Also, one of the examples includes a legend which, when used, seems to change the line colours too.
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots 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!