Changing the linestyles of individual lines in stackedplot subplots in AppDesigner.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Rusch
am 8 Aug. 2023
Kommentiert: Seth Furman
am 25 Aug. 2023
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 Kommentare
Akzeptierte Antwort
Weitere Antworten (2)
Kevin Holly
am 8 Aug. 2023
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 Kommentare
Kevin Holly
am 9 Aug. 2023
There is no other functions or listeners that edit the line's format or recreates the plots?
Seth Furman
am 25 Aug. 2023
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 Kommentare
Seth Furman
am 25 Aug. 2023
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).
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!