Changing the linestyles of individual lines in stackedplot subplots in AppDesigner.

7 ビュー (過去 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 件のコメント
Kevin Rusch
Kevin Rusch 2023 年 8 月 8 日
I've tried that too, and that didn't fix it either.
Kevin Rusch
Kevin Rusch 2023 年 8 月 8 日
@Walter Roberson -- something that may be worth noting though: If I use drawnow(), the properly formatted line is visible for a split seconds before being replaced with the unformatted line.

サインインしてコメントする。

採用された回答

Kevin Rusch
Kevin Rusch 2023 年 8 月 24 日
I've managed to solve this (or, rather, work around the issue at the heart) by creating a property app.style_tracker that keeps track of both the number of subplots and the number of lines on each subplot, and stores each line's linestyle. Whenever the stackedplot updates, I then set my LineProperties equal to this property:
if isempty(app.color_tracker) || length(app.color_tracker) < subplot_idx || isempty(app.color_tracker{subplot_idx})
app.color_tracker{subplot_idx} = [target_color];
app.style_tracker{subplot_idx} = [{target_style}];
else
app.color_tracker{subplot_idx} = [app.color_tracker{subplot_idx}; target_color];
app.style_tracker{subplot_idx} = [app.style_tracker{subplot_idx}, target_style];
end
app.VolTrace.LineProperties(subplot_idx).LineStyle = app.style_tracker{subplot_idx};
app.VolTrace.LineProperties(subplot_idx).Color = app.color_tracker{subplot_idx};
While convoluted, that seems to be the only way to work around all of stackedplot's peculiarities.

その他の回答 (2 件)

Kevin Holly
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 Rusch
Kevin Rusch 2023 年 8 月 9 日
編集済み: Kevin Rusch 2023 年 8 月 9 日
Here's the plot, the code, and the log side by side, step by step: https://i.imgur.com/hkoRZFs.gif
Kevin Holly
Kevin Holly 2023 年 8 月 9 日
There is no other functions or listeners that edit the line's format or recreates the plots?

サインインしてコメントする。


Seth Furman
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 件のコメント
Kevin Rusch
Kevin Rusch 2023 年 8 月 25 日
Absolutely. What complicated what would otherwise have been the straightforward solution to our problem was that under certain circumstances, LineProperties resets on draw when you change a single element within one of its properties, meaning that unless we reassign the entire Linestyle array at once, only the last change would persist. Hence why the only solution that ended up working was one that keeps track of changes and rewrites LineStyle with the saved value of every line within a subplot.
Seth Furman
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 ExchangeLine Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by