Skip to content

Commit 0f297a7

Browse files
Merge pull request #356 from plotly/fix_histogram2_issues_used_in_ssim_baselines_matlab_code-examples_data-distribution-plots_histogram2
Fix histogram2 issues used in ssim baselines matlab code examples data distribution plots histogram2
2 parents 9621f30 + 9bd5b80 commit 0f297a7

File tree

1 file changed

+104
-15
lines changed

1 file changed

+104
-15
lines changed

plotly/plotlyfig_aux/handlegraphics/updateHistogram2.m

+104-15
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,141 @@
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+
%-lighting settings-%
62+
obj.data{histIndex}.lighting.diffuse = 0.92;
63+
obj.data{histIndex}.lighting.ambient = 0.54;
64+
obj.data{histIndex}.lighting.specular = 1.42;
65+
obj.data{histIndex}.lighting.roughness = 0.52;
66+
obj.data{histIndex}.lighting.fresnel = 0.2;
67+
obj.data{histIndex}.lighting.vertexnormalsepsilon = 1e-12;
68+
obj.data{histIndex}.lighting.facenormalsepsilon = 1e-6;
69+
70+
%---------------------------------------------------------------------%
71+
72+
%-aspect ratio-%
73+
ar = obj.PlotOptions.AspectRatio;
74+
75+
if ~isempty(ar)
76+
if ischar(ar)
77+
obj.layout.scene.aspectmode = ar;
78+
elseif isvector(ar) && length(ar) == 3
79+
xar = ar(1);
80+
yar = ar(2);
81+
zar = ar(3);
82+
end
83+
else
84+
85+
%-define as default-%
86+
xar = max(xedges(:));
87+
yar = max(yedges(:));
88+
zar = 0.7*max([xar, yar]);
89+
end
90+
91+
obj.layout.scene.aspectratio.x = xar;
92+
obj.layout.scene.aspectratio.y = yar;
93+
obj.layout.scene.aspectratio.z = zar;
94+
95+
%---------------------------------------------------------------------%
96+
97+
%-camera eye-%
98+
ey = obj.PlotOptions.CameraEye;
99+
100+
if ~isempty(ey)
101+
if isvector(ey) && length(ey) == 3
102+
obj.layout.scene.camera.eye.x = ey(1);
103+
obj.layout.scene.camera.eye.y = ey(2);
104+
obj.layout.scene.camera.eye.z = ey(3);
105+
end
106+
else
107+
108+
%-define as default-%
109+
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
110+
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
111+
if zar>0 zfac = 0.2; else zfac = -0.2; end
112+
113+
obj.layout.scene.camera.eye.x = xey + xfac*xey;
114+
obj.layout.scene.camera.eye.y = yey + yfac*yey;
115+
obj.layout.scene.camera.eye.z = zar + zfac*zar;
116+
end
117+
118+
%---------------------------------------------------------------------%
119+
120+
121+
%-zerolines hidded-%
122+
obj.layout.scene.xaxis.zeroline = false;
123+
obj.layout.scene.yaxis.zeroline = false;
124+
obj.layout.scene.zaxis.zeroline = false;
125+
126+
%---------------------------------------------------------------------%
37127

38128
%-layout bargap-%
39129
obj.layout.bargap = bargap;
40130

41-
%-layout barmode-%
42-
obj.layout.barmode = 'group';
43-
44131
%-hist name-%
45132
obj.data{histIndex}.name = hist_data.DisplayName;
46133

47134
%-hist visible-%
48135
obj.data{histIndex}.visible = strcmp(hist_data.Visible,'on');
49136

137+
%---------------------------------------------------------------------%
138+
50139
end
51140

52141

@@ -131,9 +220,9 @@
131220
ze = zeros(size(xe));
132221

133222
positions = zeros([size(xe), 3]);
134-
positions(:,:,1) = ye';
135-
positions(:,:,2) = xe';
136-
positions(:,:,3) = ze';
223+
positions(:,:,1) = xe;
224+
positions(:,:,2) = ye;
225+
positions(:,:,3) = ze;
137226

138227
[m, n, p] = size(positions);
139228
positions = reshape(positions, [m*n, p]);

0 commit comments

Comments
 (0)