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 Center および File Exchange2-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