Skip to content

Commit 6fbdb71

Browse files
Merge pull request #367 from plotly/text_annotation_levels_added_working_with_heatmap_Another_axis_improvements
text annotation levels added working with heatmap. Another axis improvements
2 parents 568f391 + 0ca0c68 commit 6fbdb71

File tree

3 files changed

+81
-27
lines changed

3 files changed

+81
-27
lines changed

plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m

+18-18
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,50 @@
3333

3434

3535
%-AXIS INDEX-%
36-
axIndex = obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis);
36+
nanns = length(obj.layout.annotations);
37+
axIndex = nanns + obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis);
3738

3839
%-CHECK FOR MULTIPLE AXES-%
39-
[xsource, ysource] = findSourceAxis(obj,axIndex);
40-
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
41-
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
40+
[xsource, ysource] = findSourceAxis(obj,anIndex);
4241

4342
%-get heatmap title name-%
4443
title_name = obj.State.Text(anIndex).Handle;
4544

4645
%-show arrow-%
47-
obj.layout.annotations{anIndex}.showarrow = false;
46+
obj.layout.annotations{axIndex}.showarrow = false;
4847

4948
%-------------------------------------------------------------------------%
5049

5150
%-anchor title to paper-%
5251
if obj.State.Text(anIndex).Title
5352
%-xref-%
54-
obj.layout.annotations{anIndex}.xref = 'paper';
53+
obj.layout.annotations{axIndex}.xref = 'paper';
5554
%-yref-%
56-
obj.layout.annotations{anIndex}.yref = 'paper';
55+
obj.layout.annotations{axIndex}.yref = 'paper';
5756
else
5857
%-xref-%
59-
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
58+
obj.layout.annotations{axIndex}.xref = ['x' num2str(xsource)];
6059
%-yref-%
61-
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
60+
obj.layout.annotations{axIndex}.yref = ['y' num2str(ysource)];
6261
end
6362

6463
%-------------------------------------------------------------------------%
6564

6665
%-xanchor-%
67-
obj.layout.annotations{anIndex}.xanchor = 'middle';
66+
obj.layout.annotations{axIndex}.xanchor = 'middle';
6867

6968
%-align-%
70-
obj.layout.annotations{anIndex}.align = 'middle';
69+
obj.layout.annotations{axIndex}.align = 'middle';
7170

7271
%-xanchor-%
73-
obj.layout.annotations{anIndex}.yanchor = 'top';
72+
obj.layout.annotations{axIndex}.yanchor = 'top';
7473

7574

7675
%-------------------------------------------------------------------------%
7776

7877
%-text-%
79-
obj.layout.annotations{anIndex}.text = title_name;
78+
obj.layout.annotations{axIndex}.text = sprintf('<b>%s</b>', title_name);
79+
obj.layout.annotations{axIndex}.font.size = 14;
8080

8181
%-------------------------------------------------------------------------%
8282

@@ -87,15 +87,15 @@
8787
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
8888

8989
%-x position-%
90-
obj.layout.annotations{anIndex}.x = mean(xaxis.domain);
90+
obj.layout.annotations{axIndex}.x = mean(xaxis.domain);
9191
%-y position-%
92-
% obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + obj.PlotlyDefaults.TitleHeight);
93-
obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + 0.04);
92+
obj.layout.annotations{axIndex}.y = (yaxis.domain(2) + 0.04);
9493
else
9594
%-x position-%
96-
obj.layout.annotations{anIndex}.x = text_data.Position(1);
95+
obj.layout.annotations{axIndex}.x = text_data.Position(1);
9796
%-y position-%
98-
obj.layout.annotations{anIndex}.y = text_data.Position(2);
97+
obj.layout.annotations{axIndex}.y = text_data.Position(2);
9998
end
10099

100+
%-------------------------------------------------------------------------%
101101
end

plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m

+54-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
%-HEATMAP DATA STRUCTURE- %
66
heat_data = get(obj.State.Plot(heatIndex).Handle);
77

8+
%-CHECK FOR MULTIPLE AXES-%
9+
[xsource, ysource] = findSourceAxis(obj,heatIndex);
10+
811
%-------------------------------------------------------------------------%
912

1013
%-heatmap type-%
@@ -13,9 +16,13 @@
1316
%-------------------------------------------------------------------------%
1417

1518
%-format data-%
16-
obj.data{heatIndex}.x = heat_data.XDisplayData;
17-
obj.data{heatIndex}.y = heat_data.YDisplayData(end:-1:1, :);
18-
obj.data{heatIndex}.z = heat_data.ColorDisplayData(end:-1:1, :);
19+
xdata = heat_data.XDisplayData;
20+
ydata = heat_data.YDisplayData(end:-1:1, :);
21+
cdata = heat_data.ColorDisplayData(end:-1:1, :);
22+
23+
obj.data{heatIndex}.x = xdata;
24+
obj.data{heatIndex}.y = ydata;
25+
obj.data{heatIndex}.z = cdata;
1926
obj.data{heatIndex}.connectgaps = false;
2027
obj.data{heatIndex}.hoverongaps = false;
2128

@@ -54,7 +61,51 @@
5461

5562
%-hist visible-%
5663
obj.data{heatIndex}.visible = strcmp(heat_data.Visible,'on');
64+
obj.data{heatIndex}.opacity = 0.95;
65+
66+
%-------------------------------------------------------------------------%
67+
68+
%-setting annotation text-%
69+
c = 1;
70+
maxcol = max(cdata(:));
71+
72+
for n = 1:size(cdata, 2)
73+
for m = 1:size(cdata, 1)
74+
75+
%-text-%
76+
ann{c}.text = num2str(round(cdata(m,n), 2));
77+
ann{c}.x = n-1;
78+
ann{c}.y = m-1;
79+
ann{c}.showarrow = false;
80+
81+
%-font-%
82+
ann{c}.font.size = heat_data.FontSize*1.15;
83+
ann{c}.font.family = matlab2plotlyfont(heat_data.FontName);
84+
85+
if cdata(m,n) < 0.925*maxcol
86+
col = [0,0,0];
87+
else
88+
col = [255,255,255];
89+
end
90+
91+
ann{c}.font.color = sprintf('rgb(%f,%f,%f)', col);
92+
93+
c = c+1;
94+
end
95+
end
5796

5897
%-------------------------------------------------------------------------%
5998

99+
%-set annotations to layout-%
100+
obj.layout = setfield(obj.layout, 'annotations', ann);
101+
102+
%-------------------------------------------------------------------------%
103+
104+
%-set backgroud color if any NaN in cdata-%
105+
if any(isnan(cdata(:)))
106+
obj.layout.plot_bgcolor = 'rgb(40,40,40)';
107+
obj.data{heatIndex}.opacity = 1;
108+
end
109+
110+
%-------------------------------------------------------------------------%
60111
end

plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
% col = eval(['255*axis_data.' axisName 'Color;']);
5454
axiscol = 'rgb(150, 150, 150)';
55-
% axiscol = 'black';
5655

5756
%-axis linecolor-%
5857
axis.linecolor = axiscol;
@@ -61,11 +60,11 @@
6160
%-axis tickfont-%
6261
axis.tickfont.color = 'black';
6362
%-axis grid color-%
64-
axis.gridcolor = axiscol;
63+
axis.gridcolor = 'rgb(0, 0, 0)';
6564

6665
%-------------------------------------------------------------------------%
6766

68-
axis.showgrid = false;
67+
axis.showgrid = true;
6968

7069
%-------------------------------------------------------------------------%
7170

@@ -77,10 +76,11 @@
7776
%-axis tick width-%
7877
axis.tickwidth = linewidth;
7978
%-axis grid width-%
80-
axis.gridwidth = linewidth;
79+
axis.gridwidth = linewidth*1.2;
8180

8281
%-------------------------------------------------------------------------%
8382

83+
%-setting ticks-%
8484
axis.ticks = 'inside';
8585
axis.mirror = true;
8686

@@ -92,7 +92,8 @@
9292
axis.autorange = true;
9393
axis.ticktext = labels;
9494
axis.tickvals = vals;
95-
axis.showtickprefix = 'none';
95+
axis.autotick = false;
96+
axis.tickson = 'boundaries';
9697

9798
%-------------------------------LABELS------------------------------------%
9899

@@ -111,12 +112,14 @@
111112
%-------------------------------------------------------------------------%
112113

113114
%-axis title font size-%
114-
axis.titlefont.size = axis_data.FontSize*1.2;
115+
axis.titlefont.size = axis_data.FontSize*1.3;
116+
axis.tickfont.size = axis_data.FontSize*1.15;
115117

116118
%-------------------------------------------------------------------------%
117119

118120
%-axis title font family-%
119121
axis.titlefont.family = matlab2plotlyfont(axis_data.FontName);
122+
axis.tickfont.family = matlab2plotlyfont(axis_data.FontName);
120123

121124
%-------------------------------------------------------------------------%
122125

0 commit comments

Comments
 (0)