Skip to content

text annotation levels added working with heatmap. Another axis improvements #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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('<b>%s</b>', title_name);
obj.layout.annotations{axIndex}.font.size = 14;

%-------------------------------------------------------------------------%

Expand All @@ -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
57 changes: 54 additions & 3 deletions plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m
Original file line number Diff line number Diff line change
Expand Up @@ -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-%
Expand All @@ -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;

Expand Down Expand Up @@ -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
15 changes: 9 additions & 6 deletions plotly/plotlyfig_aux/helpers/extractHeatmapAxisData.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

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

%-axis linecolor-%
axis.linecolor = axiscol;
Expand All @@ -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;

%-------------------------------------------------------------------------%

Expand All @@ -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;

Expand All @@ -92,7 +92,8 @@
axis.autorange = true;
axis.ticktext = labels;
axis.tickvals = vals;
axis.showtickprefix = 'none';
axis.autotick = false;
axis.tickson = 'boundaries';

%-------------------------------LABELS------------------------------------%

Expand All @@ -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);

%-------------------------------------------------------------------------%

Expand Down