Skip to content

Commit 8cb0b43

Browse files
Fix axis detection logic for heatmaps
1 parent 5876a5c commit 8cb0b43

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

plotly/Test_plotlyfig.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,8 @@ function testHeatmapData(tc)
11391139

11401140
tc.verifyNumElements(p.data, 1);
11411141
tc.verifyEqual(rmfield(p.data{1}, "colorscale"), struct( ...
1142+
xaxis = "x1", ...
1143+
yaxis = "y1", ...
11421144
type = "heatmap", ...
11431145
x = {num2cell(num2str((1:5)'))}, ...
11441146
y = {num2cell(num2str(flip(1:5)'))}, ...
@@ -2443,6 +2445,47 @@ function testSemilogxPlotData(tc)
24432445
), AbsTol=1e-15);
24442446
end
24452447

2448+
function testTiledLayoutHeatmap(tc)
2449+
fig = figure("Visible","off");
2450+
data = [1 2; 3 4];
2451+
tiledlayout(2,2);
2452+
for i = 1:4
2453+
nexttile;
2454+
heatmap(data);
2455+
end
2456+
2457+
p = plotlyfig(fig,"visible","off");
2458+
2459+
tc.verifyNumElements(p.data, 4);
2460+
tc.verifyEqual(rmfield(p.data{1}, "colorscale"), struct( ...
2461+
xaxis = "x1", ...
2462+
yaxis = "y1", ...
2463+
type = "heatmap", ...
2464+
x = {num2cell(num2str((1:2)'))}, ...
2465+
y = {num2cell(num2str(flip(1:2)'))}, ...
2466+
z = flip(data), ...
2467+
connectgaps = false, ...
2468+
hoverongaps = false, ...
2469+
hoverinfo = "text", ...
2470+
text = flip(data), ...
2471+
hoverlabel = struct( ...
2472+
bgcolor = "white" ...
2473+
), ...
2474+
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+
), ...
2482+
visible = true, ...
2483+
opacity = 0.9500, ...
2484+
showlegend = false, ...
2485+
name = "" ...
2486+
));
2487+
end
2488+
24462489
function testGroupedBarPlotData(tc)
24472490
fig = figure("Visible","off");
24482491
y = [2 5 3; 6 1 4; 3 7 2];

plotly/plotlyfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function validate(obj)
409409

410410
% find axes of figure
411411
ax = findobj(obj.State.Figure.Handle, ...
412-
{'Type','axes','-or','Type','PolarAxes'}, ...
412+
{'Type','axes','-or','Type','PolarAxes','-or','Type','heatmap'}, ...
413413
'-and',{'Tag','','-or','Tag','PlotMatrixBigAx', ...
414414
'-or','Tag','PlotMatrixScatterAx', ...
415415
'-or','Tag','PlotMatrixHistAx'});

plotly/plotlyfig_aux/core/updateAxis.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
axisData.FontUnits = 'points';
5353
end
5454

55-
%-check if headmap axis-%
55+
%-check if heatmap axis-%
5656
isHeatmapAxis = axisData.Type == "heatmap";
5757
obj.PlotOptions.is_headmap_axis = isHeatmapAxis;
5858

@@ -64,13 +64,10 @@
6464
if isHeatmapAxis
6565
xaxis = extractHeatmapAxisData(obj,axisData, 'X');
6666
xExponentFormat = 0;
67-
else
68-
[xaxis, xExponentFormat] = extractAxisData(obj,axisData, 'X');
69-
end
70-
if isHeatmapAxis
7167
yaxis = extractHeatmapAxisData(obj,axisData, 'Y');
7268
yExponentFormat = 0;
7369
else
70+
[xaxis, xExponentFormat] = extractAxisData(obj,axisData, 'X');
7471
[yaxis, yExponentFormat] = extractAxisData(obj,axisData, 'Y');
7572
end
7673

plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
function data = updateHeatmap(obj,heatIndex)
22
%-HEATMAP DATA STRUCTURE- %
33
heat_data = obj.State.Plot(heatIndex).Handle;
4+
axIndex = obj.getAxisIndex(obj.State.Plot(heatIndex).AssociatedAxis);
5+
[xSource, ySource] = findSourceAxis(obj,axIndex);
6+
7+
data.xaxis = "x" + xSource;
8+
data.yaxis = "y" + ySource;
49

510
data.type = "heatmap";
611

0 commit comments

Comments
 (0)