Skip to content

Commit 893bd42

Browse files
legend position improvement
1 parent 3f12396 commit 893bd42

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

plotly/fig2plotly_aux/extractLegend.m

+29-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,35 @@
1111
if strcmp(a.Visible, 'on')
1212

1313
%POSITION
14-
legend.x = a.Position(1)+a.Position(3)/2;
15-
legend.y = a.Position(2)+a.Position(4)/2;
16-
legend.xanchor = 'middle';
17-
legend.yanchor = 'middle';
18-
14+
x_ref = a.Position(1)+a.Position(3)/2;
15+
y_ref = a.Position(2)+a.Position(4)/2;
16+
if x_ref>0.333
17+
if x_ref>0.666
18+
legend.x = a.Position(1)+a.Position(3);
19+
legend.xanchor = 'right';
20+
else
21+
legend.x = a.Position(1)+a.Position(3)/2;
22+
legend.xanchor = 'middle';
23+
end
24+
else
25+
legend.x = a.Position(1);
26+
legend.xanchor = 'left';
27+
end
28+
29+
if y_ref>0.333
30+
if y_ref>0.666
31+
legend.y = a.Position(2)+a.Position(4);
32+
legend.yanchor = 'top';
33+
else
34+
legend.y = a.Position(2)+a.Position(4)/2;
35+
legend.yanchor = 'middle';
36+
end
37+
else
38+
legend.y = a.Position(2);
39+
legend.yanchor = 'bottom';
40+
end
41+
42+
1943
end
2044

2145
end

0 commit comments

Comments
 (0)