Stackedplot of a multi-column tametable: how to plot each line with a different color

10 次查看(过去 30 天)
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?

采纳的回答

Geoff Hayes
Geoff Hayes 2019-2-26
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by