Skip to content

Commit 4c4bc6e

Browse files
Fix issue with axis of left histogram in scatterhist plot
1 parent 0e45f8a commit 4c4bc6e

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

plotly/Test_plotlyfig.m

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ function testScatterHistPlotData(tc)
17411741
yaxis = "y2", ...
17421742
type = "bar", ...
17431743
name = '', ...
1744-
x = [0.8 1.2], ...
1744+
x = [1.2 0.8], ...
17451745
width = [0.5 0.5], ...
17461746
y = [0.25 0.75], ...
17471747
orientation = "h", ...
@@ -1777,6 +1777,45 @@ function testScatterHistPlotData(tc)
17771777
), AbsTol=1e-15);
17781778
end
17791779

1780+
function testScatterHistPlotLayout(tc)
1781+
fig = figure(Visible="off");
1782+
x = [0.15 0.19 0.04 0.64 0.28 0.54 0.70 0.50 0.54 0.45];
1783+
y = [0.12 0.49 0.85 0.87 0.27 0.21 0.56 0.64 0.42 0.21];
1784+
scatterhist(x,y);
1785+
1786+
p = plotlyfig(fig,"visible","off");
1787+
1788+
tc.verifyEqual(p.layout.xaxis1.range, [-0.0549, 0.9549], AbsTol=1e-15);
1789+
tc.verifyEqual(p.layout.xaxis1.domain, ...
1790+
[fig.Children(4).Position(1), sum(fig.Children(4).Position([1 3]))]);
1791+
tc.verifyEqual(p.layout.xaxis1.anchor, "y1");
1792+
1793+
tc.verifyEqual(p.layout.yaxis1.range, [-0.061, 1.061], AbsTol=1e-15);
1794+
tc.verifyEqual(p.layout.yaxis1.domain, ...
1795+
[fig.Children(4).Position(2), sum(fig.Children(4).Position([2 4]))]);
1796+
tc.verifyEqual(p.layout.yaxis1.anchor, "x1");
1797+
1798+
tc.verifyEqual(p.layout.xaxis2.range, [-0.012, 1.212]);
1799+
tc.verifyEqual(p.layout.xaxis2.domain, ...
1800+
[fig.Children(3).Position(1), sum(fig.Children(3).Position([1 3]))]);
1801+
tc.verifyEqual(p.layout.xaxis2.anchor, "y2");
1802+
1803+
tc.verifyEqual(p.layout.yaxis2.range, [-0.061, 1.061], AbsTol=1e-15);
1804+
tc.verifyEqual(p.layout.yaxis2.domain, ...
1805+
[fig.Children(3).Position(2), sum(fig.Children(3).Position([2 4]))]);
1806+
tc.verifyEqual(p.layout.yaxis2.anchor, "x2");
1807+
1808+
tc.verifyEqual(p.layout.xaxis3.range, [-0.0549, 0.9549], AbsTol=1e-15);
1809+
tc.verifyEqual(p.layout.xaxis3.domain, ...
1810+
[fig.Children(2).Position(1), sum(fig.Children(2).Position([1 3]))]);
1811+
tc.verifyEqual(p.layout.xaxis3.anchor, "y3");
1812+
1813+
tc.verifyEqual(p.layout.yaxis3.range, [-0.013333333333333332, 1.3466666666666667]);
1814+
tc.verifyEqual(p.layout.yaxis3.domain, ...
1815+
[fig.Children(2).Position(2), sum(fig.Children(2).Position([2 4]))]);
1816+
tc.verifyEqual(p.layout.yaxis3.anchor, "x3");
1817+
end
1818+
17801819
function testGroupedKernelScatterHistPlotData(tc)
17811820
fig = figure("Visible","off");
17821821
x = [0.15 0.19 0.04 0.64 0.28 0.54 0.70 0.50 0.54 0.45];

plotly/plotlyfig_aux/core/updateAxis.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@
7979
axisPos(3:4) = min(axisPos(3:4));
8080
end
8181

82+
if (ischar(axisData.Tag) || isstring(axisData.Tag)) && axisData.Tag == "yhist"
83+
% scatterhist() function
84+
[xaxis, yaxis] = deal(yaxis,xaxis);
85+
[xaxis.side, yaxis.side] = deal(yaxis.side,xaxis.side);
86+
xaxis.range = flip(xaxis.range);
87+
end
88+
8289
xaxis.domain = min([axisPos(1) sum(axisPos([1,3]))], 1);
8390
scene.domain.x = xaxis.domain;
8491
yaxis.domain = min([axisPos(2) sum(axisPos([2,4]))], 1);

plotly/plotlyfig_aux/handlegraphics/updateHistogram.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@
123123
if axisData.Tag == "yhist"
124124
% scatterhist() function
125125
data.orientation = "h";
126-
temp = data.x;
127-
data.x = flip(data.y);
128-
data.y = temp;
126+
[data.x, data.y] = deal(data.y, data.x);
129127
end
130128

131129
data.name = hist_data.DisplayName;

0 commit comments

Comments
 (0)