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