Skip to content

Commit f63bce2

Browse files
committed
fix: issues with colors and legends for multiple stackedplots
1 parent a6d3af2 commit f63bce2

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

resources/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## Software
77

8+
- (All) Fix issues with colors and legends for multiple stackedplots
89
- (IMAP) Check there is data before enabling auto-compression event in `mag.imap.view.Field`
910

1011
## Package

src/visualize/+mag/+graphics/+chart/Stackedplot.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838

3939
Ny = width(yData);
4040

41-
if isempty(this.Colors) || (Ny > size(this.Colors, 1))
41+
if height(this.Colors) == 1
42+
colors = repmat(this.Colors, Ny, 1);
43+
elseif isempty(this.Colors) || (Ny > height(this.Colors))
4244
error("Mismatch in number of colors for number of plots.");
45+
else
46+
colors = this.Colors;
4347
end
4448

4549
% Check if layout already has a stack layout.
@@ -61,7 +65,7 @@
6165
hold(ax, "on");
6266
resetAxesHold = onCleanup(@() hold(ax, "off"));
6367

64-
graph(y) = plot(ax, xData, yData(:, y), this.MarkerStyle{:}, this.LineCustomization{:}, Color = this.Colors(y, :));
68+
graph(y) = plot(ax, xData, yData(:, y), this.MarkerStyle{:}, this.LineCustomization{:}, Color = colors(y, :));
6569

6670
if this.EventsVisible && ~isempty(data.Properties.Events)
6771
this.addEventsData(ax, data);

src/visualize/+mag/+graphics/+style/Stackedplot.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@
4949
xlabel(axes, this.XLabel);
5050
xlim(axes, this.XLimits);
5151

52-
l = matlab.graphics.primitive.Text.empty(0, numel(axes));
52+
t = matlab.graphics.primitive.Text.empty(0, numel(axes));
5353

5454
if ~isempty(this.YLabels)
5555

5656
for i = 1:numel(this.YLabels)
57-
l(i) = ylabel(axes(i), this.YLabels(i));
57+
t(i) = ylabel(axes(i), this.YLabels(i));
5858
end
5959
end
6060

6161
if this.RotateLabels
62-
[l.Rotation] = deal(0);
62+
[t.Rotation] = deal(0);
6363
end
6464

6565
ylim(axes, this.YLimits);
@@ -72,7 +72,7 @@
7272
this.applyGridStyle(axes);
7373

7474
% Add legend.
75-
l = this.applyLegendStyle(axes);
75+
l = this.applyLegendStyle(axes(1));
7676

7777
if ~isempty(l)
7878
l.Layout.Tile = this.LegendLocation;

0 commit comments

Comments
 (0)