Changing the linestyles of individual lines in stackedplot subplots in AppDesigner.
6 ビュー (過去 30 日間)
古いコメントを表示
Per the documentation page for StackedLineProperties, we can change the LineStyle for individual plots -- however, there doesn't seem to be any documentation for how one can edit the LineStyle for individual lines within subplots. It's possible to accomplish this in regular MATLAB using NodeChildren as such:
However, while using this method in AppDesigner does update the property, the actual plot itself does not reflect the change:
ax_children = findobj(app.VolTrace.NodeChildren, 'Type','Axes');
before = app.VolTrace.NodeChildren(app.VolTrace.NodeChildren == ax_children(subplot_idx)).Children(idx)
set(app.VolTrace.NodeChildren(app.VolTrace.NodeChildren == ax_children(subplot_idx)).Children(idx), 'Color', app.neuron_info.getNeuronColor(neuron))
if strcmp(neuron(end),'L')
set(app.VolTrace.NodeChildren(app.VolTrace.NodeChildren == ax_children(subplot_idx)).Children(idx), 'LineStyle', '--')
elseif strcmp(neuron(end),'R')
set(app.VolTrace.NodeChildren(app.VolTrace.NodeChildren == ax_children(subplot_idx)).Children(idx), 'LineStyle', '-')
end
after = app.VolTrace.NodeChildren(app.VolTrace.NodeChildren == ax_children(subplot_idx)).Children(idx)
before =
Line (IL1DL) with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 … ]
YData: [1.5333 1.7333 1.3333 1.3333 1.6000 1.2000 1.6000 1.3333 1.2000 1.2000 1.2667 1.4000 1.2000 1.2667 1.3333 1.4667 1.2000 1.0667 1.2000 1.4000 1.1333 1.4000 1.4000 … ]
Show all properties
after =
Line (IL1DL) with properties:
Color: [0.9725 0.3529 0.2471]
LineStyle: '--'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 … ]
YData: [1.5333 1.7333 1.3333 1.3333 1.6000 1.2000 1.6000 1.3333 1.2000 1.2000 1.2667 1.4000 1.2000 1.2667 1.3333 1.4667 1.2000 1.0667 1.2000 1.4000 1.1333 1.4000 1.4000 … ]
Show all properties
Any way to get this to work in AppDesigner?
3 件のコメント
採用された回答
その他の回答 (2 件)
Kevin Holly
2023 年 8 月 8 日
I made an app to test this (see attached). I was able to replicate it in R2022b Update 5, but not R2023a. As Walter suggested, inserting a drawnow after the stackedplot is created and before changing the Linestyle, fixes the problem. Note, without the drawnow, the following error occurs:
Index exceeds the number of array elements. Index must not exceed 0.
Error in stackedplotChildren/PlotButtonPushed (line 18)
set(s.NodeChildren(4).Children(1),'Linestyle','--');
If you go to debug mode and then run the line, it works.
6 件のコメント
Kevin Holly
2023 年 8 月 9 日
There is no other functions or listeners that edit the line's format or recreates the plots?
Seth Furman
2023 年 8 月 25 日
The correct way to set the line style of individual lines when using stackedplot is to set LineProperties(i) to an array of values, where i is the index of the subplot containing the line.
rng(0,"twister");
X = randi([0,10],[10,2]);
T1 = table(X,X);
s = stackedplot(T1);
s.LineProperties(2).LineStyle = ["-","--"];
The NodeChildren of a StackedLineChart is undocumented and modifications to line objects through NodeChildren will not persist.
2 件のコメント
Seth Furman
2023 年 8 月 25 日
Could you provide an example where "LineProperties resets on draw when you change a single element within one of its properties" so I can better understand your use case? Typically StackedLineChart tries to preserve LineProperties unless the underlying data changes (such as when the SourceTable property is modified).
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!