From 0ca0c682b177cdd84cd7f4473b9546749c0dbd6e Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Tue, 31 Aug 2021 17:09:27 -0400 Subject: [PATCH] text annotation levels added working with heatmap. Another axis improvements --- .../core/updateHeatmapAnnotation.m | 36 ++++++------ .../handlegraphics/updateHeatmap.m | 57 ++++++++++++++++++- .../helpers/extractHeatmapAxisData.m | 15 +++-- 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m b/plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m index cedb6b2b..ba43acc8 100644 --- a/plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m +++ b/plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m @@ -33,50 +33,50 @@ %-AXIS INDEX-% -axIndex = obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis); +nanns = length(obj.layout.annotations); +axIndex = nanns + obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis); %-CHECK FOR MULTIPLE AXES-% -[xsource, ysource] = findSourceAxis(obj,axIndex); -eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); -eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); +[xsource, ysource] = findSourceAxis(obj,anIndex); %-get heatmap title name-% title_name = obj.State.Text(anIndex).Handle; %-show arrow-% -obj.layout.annotations{anIndex}.showarrow = false; +obj.layout.annotations{axIndex}.showarrow = false; %-------------------------------------------------------------------------% %-anchor title to paper-% if obj.State.Text(anIndex).Title %-xref-% - obj.layout.annotations{anIndex}.xref = 'paper'; + obj.layout.annotations{axIndex}.xref = 'paper'; %-yref-% - obj.layout.annotations{anIndex}.yref = 'paper'; + obj.layout.annotations{axIndex}.yref = 'paper'; else %-xref-% - obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)]; + obj.layout.annotations{axIndex}.xref = ['x' num2str(xsource)]; %-yref-% - obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)]; + obj.layout.annotations{axIndex}.yref = ['y' num2str(ysource)]; end %-------------------------------------------------------------------------% %-xanchor-% -obj.layout.annotations{anIndex}.xanchor = 'middle'; +obj.layout.annotations{axIndex}.xanchor = 'middle'; %-align-% -obj.layout.annotations{anIndex}.align = 'middle'; +obj.layout.annotations{axIndex}.align = 'middle'; %-xanchor-% -obj.layout.annotations{anIndex}.yanchor = 'top'; +obj.layout.annotations{axIndex}.yanchor = 'top'; %-------------------------------------------------------------------------% %-text-% -obj.layout.annotations{anIndex}.text = title_name; +obj.layout.annotations{axIndex}.text = sprintf('%s', title_name); +obj.layout.annotations{axIndex}.font.size = 14; %-------------------------------------------------------------------------% @@ -87,15 +87,15 @@ eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); %-x position-% - obj.layout.annotations{anIndex}.x = mean(xaxis.domain); + obj.layout.annotations{axIndex}.x = mean(xaxis.domain); %-y position-% - % obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + obj.PlotlyDefaults.TitleHeight); - obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + 0.04); + obj.layout.annotations{axIndex}.y = (yaxis.domain(2) + 0.04); else %-x position-% - obj.layout.annotations{anIndex}.x = text_data.Position(1); + obj.layout.annotations{axIndex}.x = text_data.Position(1); %-y position-% - obj.layout.annotations{anIndex}.y = text_data.Position(2); + obj.layout.annotations{axIndex}.y = text_data.Position(2); end +%-------------------------------------------------------------------------% end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m b/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m index 6d446b85..8fb11017 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m @@ -5,6 +5,9 @@ %-HEATMAP DATA STRUCTURE- % heat_data = get(obj.State.Plot(heatIndex).Handle); +%-CHECK FOR MULTIPLE AXES-% +[xsource, ysource] = findSourceAxis(obj,heatIndex); + %-------------------------------------------------------------------------% %-heatmap type-% @@ -13,9 +16,13 @@ %-------------------------------------------------------------------------% %-format data-% -obj.data{heatIndex}.x = heat_data.XDisplayData; -obj.data{heatIndex}.y = heat_data.YDisplayData(end:-1:1, :); -obj.data{heatIndex}.z = heat_data.ColorDisplayData(end:-1:1, :); +xdata = heat_data.XDisplayData; +ydata = heat_data.YDisplayData(end:-1:1, :); +cdata = heat_data.ColorDisplayData(end:-1:1, :); + +obj.data{heatIndex}.x = xdata; +obj.data{heatIndex}.y = ydata; +obj.data{heatIndex}.z = cdata; obj.data{heatIndex}.connectgaps = false; obj.data{heatIndex}.hoverongaps = false; @@ -54,7 +61,51 @@ %-hist visible-% obj.data{heatIndex}.visible = strcmp(heat_data.Visible,'on'); +obj.data{heatIndex}.opacity = 0.95; + +%-------------------------------------------------------------------------% + +%-setting annotation text-% +c = 1; +maxcol = max(cdata(:)); + +for n = 1:size(cdata, 2) + for m = 1:size(cdata, 1) + + %-text-% + ann{c}.text = num2str(round(cdata(m,n), 2)); + ann{c}.x = n-1; + ann{c}.y = m-1; + ann{c}.showarrow = false; + + %-font-% + ann{c}.font.size = heat_data.FontSize*1.15; + ann{c}.font.family = matlab2plotlyfont(heat_data.FontName); + + if cdata(m,n) < 0.925*maxcol + col = [0,0,0]; + else + col = [255,255,255]; + end + + ann{c}.font.color = sprintf('rgb(%f,%f,%f)', col); + + c = c+1; + end +end %-------------------------------------------------------------------------% +%-set annotations to layout-% +obj.layout = setfield(obj.layout, 'annotations', ann); + +%-------------------------------------------------------------------------% + +%-set backgroud color if any NaN in cdata-% +if any(isnan(cdata(:))) + obj.layout.plot_bgcolor = 'rgb(40,40,40)'; + obj.data{heatIndex}.opacity = 1; +end + +%-------------------------------------------------------------------------% end diff --git a/plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m b/plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m index aa9778e9..e70ba08d 100644 --- a/plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m +++ b/plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m @@ -52,7 +52,6 @@ % col = eval(['255*axis_data.' axisName 'Color;']); axiscol = 'rgb(150, 150, 150)'; -% axiscol = 'black'; %-axis linecolor-% axis.linecolor = axiscol; @@ -61,11 +60,11 @@ %-axis tickfont-% axis.tickfont.color = 'black'; %-axis grid color-% -axis.gridcolor = axiscol; +axis.gridcolor = 'rgb(0, 0, 0)'; %-------------------------------------------------------------------------% -axis.showgrid = false; +axis.showgrid = true; %-------------------------------------------------------------------------% @@ -77,10 +76,11 @@ %-axis tick width-% axis.tickwidth = linewidth; %-axis grid width-% -axis.gridwidth = linewidth; +axis.gridwidth = linewidth*1.2; %-------------------------------------------------------------------------% +%-setting ticks-% axis.ticks = 'inside'; axis.mirror = true; @@ -92,7 +92,8 @@ axis.autorange = true; axis.ticktext = labels; axis.tickvals = vals; -axis.showtickprefix = 'none'; +axis.autotick = false; +axis.tickson = 'boundaries'; %-------------------------------LABELS------------------------------------% @@ -111,12 +112,14 @@ %-------------------------------------------------------------------------% %-axis title font size-% -axis.titlefont.size = axis_data.FontSize*1.2; +axis.titlefont.size = axis_data.FontSize*1.3; +axis.tickfont.size = axis_data.FontSize*1.15; %-------------------------------------------------------------------------% %-axis title font family-% axis.titlefont.family = matlab2plotlyfont(axis_data.FontName); +axis.tickfont.family = matlab2plotlyfont(axis_data.FontName); %-------------------------------------------------------------------------%