Skip to content

Commit b6c6022

Browse files
fix issues with histogram2 function used in ssim_baselines/matlab/code-examples/data-distribution-plots/histogram2
1 parent f68c9db commit b6c6022

File tree

1 file changed

+93
-15
lines changed

1 file changed

+93
-15
lines changed

Diff for: plotly/plotlyfig_aux/handlegraphics/updateHistogram2.m

+93-15
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,130 @@
11
function obj = updateHistogram2(obj,histIndex)
22

3+
%---------------------------------------------------------------------%
4+
35
%-AXIS INDEX-%
46
axIndex = obj.getAxisIndex(obj.State.Plot(histIndex).AssociatedAxis);
57

8+
%---------------------------------------------------------------------%
9+
610
%-HIST DATA STRUCTURE- %
711
hist_data = get(obj.State.Plot(histIndex).Handle);
812

13+
%---------------------------------------------------------------------%
14+
915
%-hist type-%
1016
obj.data{histIndex}.type = 'mesh3d';
1117

18+
%---------------------------------------------------------------------%
19+
1220
%-required parameters-%
1321
values = hist_data.Values;
14-
xedges = hist_data.XBinEdges;
22+
xedges = hist_data.XBinEdges;
1523
yedges = hist_data.YBinEdges;
1624

25+
sx = diff(xedges(2:end-1));
26+
sy = diff(yedges(2:end-1));
27+
28+
if isinf(xedges(1)) xedges(1) = xedges(2) - sx(1); end
29+
if isinf(yedges(1)) yedges(1) = yedges(2) - sy(1); end
30+
31+
if isinf(xedges(end)) xedges(end) = xedges(end-1) + sx(1); end
32+
if isinf(yedges(end)) yedges(end) = yedges(end-1) + sy(1); end
33+
34+
%---------------------------------------------------------------------%
35+
1736
%-get the values to use plotly's mesh3D-%
18-
bargap = 0.06;
37+
bargap = 0.05;
1938
[X, Y, Z, I, J, K] = get_plotly_mesh3d(xedges, yedges, values, bargap);
2039

40+
%---------------------------------------------------------------------%
41+
2142
%-passing parameters to mesh3D-%
2243
obj.data{histIndex}.x = X;
2344
obj.data{histIndex}.y = Y;
2445
obj.data{histIndex}.z = Z;
25-
obj.data{histIndex}.i = uint16(I-1);
26-
obj.data{histIndex}.j = uint16(J-1);
27-
obj.data{histIndex}.k = uint16(K-1);
46+
obj.data{histIndex}.i = int16(I-1);
47+
obj.data{histIndex}.j = int16(J-1);
48+
obj.data{histIndex}.k = int16(K-1);
49+
50+
%---------------------------------------------------------------------%
2851

2952
%-some settings-%
30-
obj.data{histIndex}.color=[0.8,0.8,0.8];
53+
% obj.data{histIndex}.color='rgb(0,255,0)';
3154
obj.data{histIndex}.contour.show = true;
32-
obj.data{histIndex}.contour.color = 'black';
3355
obj.data{histIndex}.contour.width = 6;
56+
obj.data{histIndex}.contour.color='rgb(0,0,0)';
3457
obj.data{histIndex}.flatshading = true;
35-
obj.data{histIndex}.bordercolor = 'black';
36-
obj.data{histIndex}.borderwidth = 6;
58+
59+
%---------------------------------------------------------------------%
60+
61+
%-aspect ratio-%
62+
ar = obj.PlotOptions.AspectRatio;
63+
64+
if ~isempty(ar)
65+
if ischar(ar)
66+
obj.layout.scene.aspectmode = ar;
67+
elseif isvector(ar) && length(ar) == 3
68+
xar = ar(1);
69+
yar = ar(2);
70+
zar = ar(3);
71+
end
72+
else
73+
74+
%-define as default-%
75+
xar = max(xedges(:));
76+
yar = max(yedges(:));
77+
zar = 0.7*max([xar, yar]);
78+
end
79+
80+
obj.layout.scene.aspectratio.x = xar;
81+
obj.layout.scene.aspectratio.y = yar;
82+
obj.layout.scene.aspectratio.z = zar;
83+
84+
%---------------------------------------------------------------------%
85+
86+
%-camera eye-%
87+
ey = obj.PlotOptions.CameraEye;
88+
89+
if ~isempty(ey)
90+
if isvector(ey) && length(ey) == 3
91+
obj.layout.scene.camera.eye.x = ey(1);
92+
obj.layout.scene.camera.eye.y = ey(2);
93+
obj.layout.scene.camera.eye.z = ey(3);
94+
end
95+
else
96+
97+
%-define as default-%
98+
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
99+
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
100+
if zar>0 zfac = 0.2; else zfac = -0.2; end
101+
102+
obj.layout.scene.camera.eye.x = xey + xfac*xey;
103+
obj.layout.scene.camera.eye.y = yey + yfac*yey;
104+
obj.layout.scene.camera.eye.z = zar + zfac*zar;
105+
end
106+
107+
%---------------------------------------------------------------------%
108+
109+
110+
%-zerolines hidded-%
111+
obj.layout.scene.xaxis.zeroline = false;
112+
obj.layout.scene.yaxis.zeroline = false;
113+
obj.layout.scene.zaxis.zeroline = false;
114+
115+
%---------------------------------------------------------------------%
37116

38117
%-layout bargap-%
39118
obj.layout.bargap = bargap;
40119

41-
%-layout barmode-%
42-
obj.layout.barmode = 'group';
43-
44120
%-hist name-%
45121
obj.data{histIndex}.name = hist_data.DisplayName;
46122

47123
%-hist visible-%
48124
obj.data{histIndex}.visible = strcmp(hist_data.Visible,'on');
49125

126+
%---------------------------------------------------------------------%
127+
50128
end
51129

52130

@@ -131,9 +209,9 @@
131209
ze = zeros(size(xe));
132210

133211
positions = zeros([size(xe), 3]);
134-
positions(:,:,1) = ye';
135-
positions(:,:,2) = xe';
136-
positions(:,:,3) = ze';
212+
positions(:,:,1) = xe;
213+
positions(:,:,2) = ye;
214+
positions(:,:,3) = ze;
137215

138216
[m, n, p] = size(positions);
139217
positions = reshape(positions, [m*n, p]);

0 commit comments

Comments
 (0)