Skip to content

Commit adf7fa6

Browse files
Fix scatter hist plots with grouped data
1 parent 9f165da commit adf7fa6

File tree

4 files changed

+268
-4
lines changed

4 files changed

+268
-4
lines changed

plotly/Test_plotlyfig.m

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,267 @@ function testScatterHistPlotData(tc)
17561756
), AbsTol=1e-15);
17571757
end
17581758

1759+
function testGroupedKernelScatterHistPlotData(tc)
1760+
fig = figure("Visible","off");
1761+
x = [0.15 0.19 0.04 0.64 0.28 0.54 0.70 0.50 0.54 0.45];
1762+
y = [0.12 0.49 0.85 0.87 0.27 0.21 0.56 0.64 0.42 0.21];
1763+
species = [repelem("setosa",4) repelem("versicolor",4) repelem("virginica",2)]';
1764+
1765+
scatterhist(x,y,"Group",species,"Kernel","on");
1766+
1767+
p = plotlyfig(fig,"visible","off");
1768+
1769+
tc.verifyNumElements(p.data, 12);
1770+
tc.verifyEqual(p.data{1}, struct( ...
1771+
"type", "scatter", ...
1772+
"xaxis", "x1", ...
1773+
"yaxis", "y1", ...
1774+
"visible", true, ...
1775+
"name", 'setosa', ...
1776+
"mode", 'markers', ...
1777+
"x", x(species == "setosa"), ...
1778+
"y", y(species == "setosa"), ...
1779+
"line", struct(), ...
1780+
"marker", struct( ...
1781+
"size", 3.6, ...
1782+
"symbol", "circle", ...
1783+
"line", struct( ...
1784+
"width", 0.5, ...
1785+
"color", "rgb(0,114,189)" ...
1786+
), ...
1787+
"color", "rgba(0,0,0,0)" ...
1788+
), ...
1789+
"showlegend", true ...
1790+
), AbsTol=1e-15);
1791+
tc.verifyEqual(p.data{2}, struct( ...
1792+
"type", "scatter", ...
1793+
"xaxis", "x1", ...
1794+
"yaxis", "y1", ...
1795+
"visible", true, ...
1796+
"name", 'versicolor', ...
1797+
"mode", 'markers', ...
1798+
"x", x(species == "versicolor"), ...
1799+
"y", y(species == "versicolor"), ...
1800+
"line", struct(), ...
1801+
"marker", struct( ...
1802+
"size", 3.6, ...
1803+
"symbol", "circle", ...
1804+
"line", struct( ...
1805+
"width", 0.5, ...
1806+
"color", "rgb(217,83,25)" ...
1807+
), ...
1808+
"color", "rgba(0,0,0,0)" ...
1809+
), ...
1810+
"showlegend", true ...
1811+
), AbsTol=1e-15);
1812+
tc.verifyEqual(p.data{3}, struct( ...
1813+
"type", "scatter", ...
1814+
"xaxis", "x1", ...
1815+
"yaxis", "y1", ...
1816+
"visible", true, ...
1817+
"name", 'virginica', ...
1818+
"mode", 'markers', ...
1819+
"x", x(species == "virginica"), ...
1820+
"y", y(species == "virginica"), ...
1821+
"line", struct(), ...
1822+
"marker", struct( ...
1823+
"size", 3.6, ...
1824+
"symbol", "circle", ...
1825+
"line", struct( ...
1826+
"width", 0.5, ...
1827+
"color", "rgb(237,177,32)" ...
1828+
), ...
1829+
"color", "rgba(0,0,0,0)" ...
1830+
), ...
1831+
"showlegend", true ...
1832+
), AbsTol=1e-15);
1833+
tc.verifyEqual(p.data{4}, []);
1834+
tc.verifyEqual(p.data{5}, struct( ...
1835+
"type", "scatter", ...
1836+
"xaxis", "x3", ...
1837+
"yaxis", "y3", ...
1838+
"name", '', ...
1839+
"mode", 'lines', ...
1840+
"x", fig.Children(3).Children(4).XData, ...
1841+
"y", fig.Children(3).Children(4).YData, ...
1842+
"line", struct( ...
1843+
"color", "rgb(0,114,189)", ...
1844+
"width", 2, ...
1845+
"dash", "solid" ...
1846+
), ...
1847+
"marker", struct( ...
1848+
"size", 3.6, ...
1849+
"line", struct( ...
1850+
"width", 2 ...
1851+
), ...
1852+
"color", "rgb(0,114,189)" ...
1853+
), ...
1854+
"visible", true, ...
1855+
"showlegend", false ...
1856+
), AbsTol=1e-15);
1857+
tc.verifyEqual(p.data{6}, struct( ...
1858+
"type", "scatter", ...
1859+
"xaxis", "x3", ...
1860+
"yaxis", "y3", ...
1861+
"name", '', ...
1862+
"mode", 'lines', ...
1863+
"x", fig.Children(3).Children(3).XData, ...
1864+
"y", fig.Children(3).Children(3).YData, ...
1865+
"line", struct( ...
1866+
"color", "rgb(217,83,25)", ...
1867+
"width", 2, ...
1868+
"dash", "dot" ...
1869+
), ...
1870+
"marker", struct( ...
1871+
"size", 3.6, ...
1872+
"line", struct( ...
1873+
"width", 2 ...
1874+
), ...
1875+
"color", "rgb(217,83,25)" ...
1876+
), ...
1877+
"visible", true, ...
1878+
"showlegend", false ...
1879+
), AbsTol=1e-15);
1880+
tc.verifyEqual(p.data{7}, struct( ...
1881+
"type", "scatter", ...
1882+
"xaxis", "x3", ...
1883+
"yaxis", "y3", ...
1884+
"name", '', ...
1885+
"mode", 'lines', ...
1886+
"x", fig.Children(3).Children(2).XData, ...
1887+
"y", fig.Children(3).Children(2).YData, ...
1888+
"line", struct( ...
1889+
"color", "rgb(237,177,32)", ...
1890+
"width", 2, ...
1891+
"dash", "dashdot" ...
1892+
), ...
1893+
"marker", struct( ...
1894+
"size", 3.6, ...
1895+
"line", struct( ...
1896+
"width", 2 ...
1897+
), ...
1898+
"color", "rgb(237,177,32)" ...
1899+
), ...
1900+
"visible", true, ...
1901+
"showlegend", false ...
1902+
), AbsTol=1e-15);
1903+
tc.verifyEqual(p.data{8}, struct( ...
1904+
"type", "scatter", ...
1905+
"xaxis", "x3", ...
1906+
"yaxis", "y3", ...
1907+
"name", '', ...
1908+
"mode", 'lines', ...
1909+
"x", [0.045 0.945], ...
1910+
"y", [0 0], ...
1911+
"line", struct( ...
1912+
"color", "rgb(0,0,0)", ...
1913+
"width", 0.5, ...
1914+
"dash", "solid" ...
1915+
), ...
1916+
"marker", struct( ...
1917+
"size", 3.6, ...
1918+
"line", struct( ...
1919+
"width", 0.5 ...
1920+
), ...
1921+
"color", "rgb(0,0,0)" ...
1922+
), ...
1923+
"visible", true, ...
1924+
"showlegend", false ...
1925+
), AbsTol=1e-15);
1926+
tc.verifyEqual(p.data{9}, struct( ...
1927+
"type", "scatter", ...
1928+
"xaxis", "x4", ...
1929+
"yaxis", "y4", ...
1930+
"name", '', ...
1931+
"mode", 'lines', ...
1932+
"x", fig.Children(2).Children(4).XData, ...
1933+
"y", fig.Children(2).Children(4).YData, ...
1934+
"line", struct( ...
1935+
"color", "rgb(0,114,189)", ...
1936+
"width", 2, ...
1937+
"dash", "solid" ...
1938+
), ...
1939+
"marker", struct( ...
1940+
"size", 3.6, ...
1941+
"line", struct( ...
1942+
"width", 2 ...
1943+
), ...
1944+
"color", "rgb(0,114,189)" ...
1945+
), ...
1946+
"visible", true, ...
1947+
"showlegend", false ...
1948+
), AbsTol=1e-15);
1949+
tc.verifyEqual(p.data{10}, struct( ...
1950+
"type", "scatter", ...
1951+
"xaxis", "x4", ...
1952+
"yaxis", "y4", ...
1953+
"name", '', ...
1954+
"mode", 'lines', ...
1955+
"x", fig.Children(2).Children(3).XData, ...
1956+
"y", fig.Children(2).Children(3).YData, ...
1957+
"line", struct( ...
1958+
"color", "rgb(217,83,25)", ...
1959+
"width", 2, ...
1960+
"dash", "dot" ...
1961+
), ...
1962+
"marker", struct( ...
1963+
"size", 3.6, ...
1964+
"line", struct( ...
1965+
"width", 2 ...
1966+
), ...
1967+
"color", "rgb(217,83,25)" ...
1968+
), ...
1969+
"visible", true, ...
1970+
"showlegend", false ...
1971+
), AbsTol=1e-15);
1972+
tc.verifyEqual(p.data{11}, struct( ...
1973+
"type", "scatter", ...
1974+
"xaxis", "x4", ...
1975+
"yaxis", "y4", ...
1976+
"name", '', ...
1977+
"mode", 'lines', ...
1978+
"x", fig.Children(2).Children(2).XData, ...
1979+
"y", fig.Children(2).Children(2).YData, ...
1980+
"line", struct( ...
1981+
"color", "rgb(237,177,32)", ...
1982+
"width", 2, ...
1983+
"dash", "dashdot" ...
1984+
), ...
1985+
"marker", struct( ...
1986+
"size", 3.6, ...
1987+
"line", struct( ...
1988+
"width", 2 ...
1989+
), ...
1990+
"color", "rgb(237,177,32)" ...
1991+
), ...
1992+
"visible", true, ...
1993+
"showlegend", false ...
1994+
), AbsTol=1e-15);
1995+
tc.verifyEqual(p.data{12}, struct( ...
1996+
"type", "scatter", ...
1997+
"xaxis", "x4", ...
1998+
"yaxis", "y4", ...
1999+
"name", '', ...
2000+
"mode", 'lines', ...
2001+
"x", [-0.026 0.766], ...
2002+
"y", [0 0], ...
2003+
"line", struct( ...
2004+
"color", "rgb(0,0,0)", ...
2005+
"width", 0.5, ...
2006+
"dash", "solid" ...
2007+
), ...
2008+
"marker", struct( ...
2009+
"size", 3.6, ...
2010+
"line", struct( ...
2011+
"width", 0.5 ...
2012+
), ...
2013+
"color", "rgb(0,0,0)" ...
2014+
), ...
2015+
"visible", true, ...
2016+
"showlegend", false ...
2017+
), AbsTol=1e-15);
2018+
end
2019+
17592020
function testTitleFont(tc)
17602021
fig = figure("Visible","off");
17612022
x = 1:10;

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
if isBoxplot(obj, dataIndex)
165165
updateBoxplot(obj, dataIndex);
166166
end
167-
case {"uimenu","uicontextmenu"}
167+
case {"uimenu","uicontextmenu","legend"}
168168
% Do nothing
169169
return
170170
otherwise

plotly/plotlyfig_aux/helpers/findLegendAxis.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
handle(getappdata(x.Handle, 'LegendPeerHandle')), ...
55
legendHandle), obj.State.Axis), 1);
66
else
7-
legendAxisIndex = find(arrayfun(@(x) isequal( ...
8-
handle(x.Handle.Legend), legendHandle), obj.State.Axis), 1);
7+
legendAxisIndex = find(arrayfun( ...
8+
@(x) isprop(x.Handle, "Legend") ...
9+
&& isequal(handle(x.Handle.Legend), legendHandle), ...
10+
obj.State.Axis ...
11+
),1);
912
end
1013

1114
legendAxis = obj.State.Axis(legendAxisIndex).Handle;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function out = specialAxisPlots()
2-
out = ["polaraxes" "stackedplot" "uicontextmenu"];
2+
out = ["polaraxes" "stackedplot" "uicontextmenu" "legend"];
33
end

0 commit comments

Comments
 (0)