Skip to content

Commit 3bbc550

Browse files
Fix colorbar position for heatmaps in tiledLayout
1 parent 8cb0b43 commit 3bbc550

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

plotly/Test_plotlyfig.m

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ function testStackedBarData(tc)
11311131
end
11321132

11331133
function testHeatmapData(tc)
1134-
fig = figure("Visible","off");
1134+
fig = figure(Visible="off");
11351135
data = magic(5);
11361136
heatmap(data);
11371137

@@ -1154,17 +1154,23 @@ function testHeatmapData(tc)
11541154
), ...
11551155
showscale = true, ...
11561156
colorbar = struct( ...
1157-
x = 0.87, ...
1158-
y = 0.52, ...
1159-
ypad = 55, ...
1160-
xpad = 0, ...
1157+
x = fig.Children.Position(1) + fig.Children.Position(3), ...
1158+
y = fig.Children.Position(2), ...
1159+
xanchor = "left", ...
1160+
yanchor = "bottom", ...
1161+
thicknessmode = "fraction", ...
1162+
thickness = fig.Children.Position(3)/10, ...
1163+
lenmode = "fraction", ...
1164+
len = fig.Children.Position(4), ...
1165+
ypad = 0, ...
1166+
xpad = 10, ...
11611167
outlinecolor = "rgb(150,150,150)" ...
11621168
), ...
11631169
visible = true, ...
11641170
opacity = 0.9500, ...
11651171
showlegend = false, ...
11661172
name = "" ...
1167-
));
1173+
), AbsTol=1e-15);
11681174
end
11691175

11701176
function testErrorbarData(tc)
@@ -2457,7 +2463,7 @@ function testTiledLayoutHeatmap(tc)
24572463
p = plotlyfig(fig,"visible","off");
24582464

24592465
tc.verifyNumElements(p.data, 4);
2460-
tc.verifyEqual(rmfield(p.data{1}, "colorscale"), struct( ...
2466+
tc.verifyEqual(rmfield(p.data{1}, ["colorscale" "colorbar"]), struct( ...
24612467
xaxis = "x1", ...
24622468
yaxis = "y1", ...
24632469
type = "heatmap", ...
@@ -2472,18 +2478,22 @@ function testTiledLayoutHeatmap(tc)
24722478
bgcolor = "white" ...
24732479
), ...
24742480
showscale = true, ...
2475-
colorbar = struct( ...
2476-
x = 0.87, ...
2477-
y = 0.52, ...
2478-
ypad = 55, ...
2479-
xpad = 0, ...
2480-
outlinecolor = "rgb(150,150,150)" ...
2481-
), ...
24822481
visible = true, ...
24832482
opacity = 0.9500, ...
24842483
showlegend = false, ...
24852484
name = "" ...
2486-
));
2485+
), AbsTol=1e-15);
2486+
tc.verifyEqual(rmfield(p.data{1}.colorbar, ["thickness" "x"]), struct( ...
2487+
y = fig.Children.Children(4).Position(2), ...
2488+
xanchor = "left", ...
2489+
yanchor = "bottom", ...
2490+
thicknessmode = "fraction", ...
2491+
lenmode = "fraction", ...
2492+
len = fig.Children.Children(4).Position(4), ...
2493+
ypad = 0, ...
2494+
xpad = 10, ...
2495+
outlinecolor = "rgb(150,150,150)" ...
2496+
), AbsTol=1e-15);
24872497
end
24882498

24892499
function testGroupedBarPlotData(tc)

plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@
3030

3131
data.showscale = false;
3232
if lower(heat_data.ColorbarVisible) == "on"
33+
xaxis = obj.layout.("xaxis" + xSource);
34+
yaxis = obj.layout.("yaxis" + ySource);
3335
data.showscale = true;
3436
data.colorbar = struct( ...
35-
"x", 0.87, ...
36-
"y", 0.52, ...
37-
"ypad", 55, ...
38-
"xpad", obj.PlotlyDefaults.MarginPad, ...
37+
"x", xaxis.domain(2), ...
38+
"y", yaxis.domain(1), ...
39+
"xanchor", "left", ...
40+
"yanchor", "bottom", ...
41+
"thicknessmode", "fraction", ...
42+
"thickness", rangeLength(xaxis.domain)/10, ...
43+
"lenmode", "fraction", ...
44+
"len", rangeLength(yaxis.domain), ...
45+
"ypad", obj.PlotlyDefaults.MarginPad, ...
46+
"xpad", 10, ...
3947
"outlinecolor", "rgb(150,150,150)" ...
4048
);
4149
end

0 commit comments

Comments
 (0)