reporting: set up legends for graphs

remove-priordens
Houtan Bastani 2014-02-11 18:26:28 +01:00
parent 0d364975db
commit fb7def044a
5 changed files with 27 additions and 51 deletions

View File

@ -54,9 +54,9 @@ o.showGrid = true;
o.showLegend = false;
o.showLegendBox = false;
o.legendLocation = 'SouthEast';
o.legendLocation = 'south east';
o.legendOrientation = 'horizontal';
o.legendFontSize = 8;
o.legendFontSize = 'tiny';
o.showZeroline = false;
@ -103,7 +103,6 @@ assert(ischar(o.figDirName), '@graph.graph: figDirName must be a string');
assert(islogical(o.showGrid), '@graph.graph: showGrid must be either true or false');
assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or false');
assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false');
assert(isint(o.legendFontSize), '@graph.graph: legendFontSize must be an integer');
assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false');
assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
@ -115,15 +114,15 @@ assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must b
assert(ischar(o.xTickLabelAnchor), '@graph.graph: xTickLabelAnchor must be a string');
valid_legend_locations = ...
{'North', 'South', 'East', 'West', ...
'NorthEast', 'SouthEast', 'NorthWest', 'SouthWest', ...
'NorthOutside', 'SouthOutside', 'EastOutside', 'WestOutside', ...
'NorthEastOutside', 'SouthEastOutside', 'NorthWestOutside', 'SouthWestOutside', ...
'Best', 'BestOutside', ...
};
{'south west','south east','north west','north east','outer north east'};
assert(any(strcmp(o.legendLocation, valid_legend_locations)), ...
['@graph.graph: legendLocation must be one of ' strjoin(valid_legend_locations, ' ')]);
valid_legend_font_sizes = {'tiny', 'scriptsize', 'footnotesize', 'small', ...
'normalsize', 'large', 'Large', 'LARGE', 'huge', 'Huge'};
assert(any(strcmp(o.legendFontSize, valid_legend_font_sizes)), ...
['@graph.graph: legendFontSize must be one of ' strjoin(valid_legend_font_sizes)]);
valid_legend_orientations = {'vertical', 'horizontal'};
assert(any(strcmp(o.legendOrientation, valid_legend_orientations)), ...
['@graph.graph: legendOrientation must be one of ' strjoin(valid_legend_orientations, ' ')]);

View File

@ -105,6 +105,18 @@ fprintf(fid, ['},\n',...
'ymax=%d,\n'...
'axis lines=box,\n'], o.width, o.height, dd.ndat, ymin, ymax);
if o.showLegend
fprintf(fid, 'legend style={');
if ~o.showLegendBox
fprintf(fid, 'draw=none,');
end
fprintf(fid, 'font=\\%s,', o.legendFontSize);
if strcmp(o.legendOrientation, 'horizontal')
fprintf(fid,'legend columns=-1,');
end
fprintf(fid, '},\nlegend pos=%s,\n', o.legendLocation);
end
if o.showGrid
fprintf(fid, 'xmajorgrids=true,\nymajorgrids=true,\n');
end
@ -136,22 +148,13 @@ end
for i=1:ne
o.series{i}.writeSeriesForGraph(fid, dd);
if o.showLegend
fprintf(fid, '\\addlegendentry{%s}\n', o.series{i}.getTexName());
end
end
fprintf(fid, '\\end{axis}\\end{tikzpicture}\n');
fprintf(fid, '\\end{axis}\n\\end{tikzpicture}\n');
if fclose(fid) == -1
error('@graph.writeGraphFile: closing %s\n', o.filename);
end
return
if o.showLegend
lh = legend(line_handles, getTexNames(o.series), ...
'orientation', o.legendOrientation, ...
'location', o.legendLocation);
set(lh, 'FontSize', o.legendFontSize);
set(lh, 'interpreter', 'latex');
if ~o.showLegendBox
legend('boxoff');
end
end
end
end

View File

@ -19,5 +19,5 @@ function s = getTexName(o)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(~isempty(o.data) && size(o.data, 2) == 1);
s = o.data.tex;
s = o.data.tex{:};
end

View File

@ -84,7 +84,7 @@ if any(stz)
thedata(stz) = 0;
end
fprintf(fid, '%%series %s\n\\addplot[color=%s,%s,line width=%fpt,forget plot,line join=round',...
fprintf(fid, '%%series %s\n\\addplot[color=%s,%s,line width=%fpt,line join=round',...
o.data.name{:}, o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
if ~isempty(o.graphMarker)
if isempty(o.graphMarkerEdgeColor)

View File

@ -1,26 +0,0 @@
function names = getTexNames(cellser)
%function names = getTexNames(cellser)
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
ne = length(cellser);
names = cell(ne, 1);
for i=1:ne
names(i) = cellser{i}.getTexName();
end
end