diff --git a/doc/dynare.texi b/doc/dynare.texi
index 7ac192c37ba723f259ab17f55f959bf47197781e..faa427b10b59701d3bb237e7976e7a768171e095 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -10765,7 +10765,7 @@ The color to use in the shaded portion of the graph. Default:
 @code{`green'}
 
 @item shadeOpacity, @code{DOUBLE}
-The opacity of the shaded area, must be in @math{[0,1]}. Default: @code{.2}
+The opacity of the shaded area, must be in @math{[0,100]}. Default: @code{20}
 
 @item title, @code{STRING}
 Title for the graph. Default: @code{none}
diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m
index 1b1735789cfedd3f95fe54e828f2ddb847b040cc..1745ac57c33275fc56bfaea5b8942f9f862c38e4 100644
--- a/matlab/reports/@graph/graph.m
+++ b/matlab/reports/@graph/graph.m
@@ -48,7 +48,7 @@ o.yrange = '';
 
 o.shade = '';
 o.shadeColor = 'green';
-o.shadeOpacity = .2;
+o.shadeOpacity = 20;
 
 o.showGrid = true;
 
@@ -105,8 +105,8 @@ assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or
 assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false');
 assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false');
 assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
-       o.shadeOpacity >= 0 && o.shadeOpacity <= 1, ...
-       '@graph.graph: o.shadeOpacity must be a real in [0 1]');
+       o.shadeOpacity >= 0 && o.shadeOpacity <= 100, ...
+       '@graph.graph: o.shadeOpacity must be a real in [0 100]');
 assert(isfloat(o.width), '@graph.graph: o.width must be a real number');
 assert(isfloat(o.height), '@graph.graph: o.height must be a real number');
 assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number');
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index e0d415a9dc7f017a600d025ff7384970fd48f1e6..7ce376aca5b916bd9498f9cc9cf7c05cf6e86699 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -55,20 +55,6 @@ else
     dd = o.xrange;
 end
 
-if isempty(o.yrange)
-    ymax = zeros(1, ne);
-    ymin = zeros(1, ne);
-    for i=1:ne
-        ymax(i) = o.series{i}.ymax(dd);
-        ymin(i) = o.series{i}.ymin(dd);
-    end
-    ymax = ceil(max(ymax));
-    ymin = floor(min(ymin));
-else
-    ymin = o.yrange(1);
-    ymax = o.yrange(2);
-end
-
 fprintf(fid, '\\begin{axis}[%%\n');
 % set tick labels
 if isempty(o.xTickLabels)
@@ -101,9 +87,13 @@ fprintf(fid, ['},\n',...
               'scale only axis,\n'...
               'xmin=1,\n'...
               'xmax=%d,\n'...
-              'ymin=%d,\n'...
-              'ymax=%d,\n'...
-              'axis lines=box,\n'], o.width, o.height, dd.ndat, ymin, ymax);
+              'axis lines=box,\n'], o.width, o.height, dd.ndat);
+
+if isempty(o.yrange)
+    fprintf(fid, 'enlarge y limits=true,\n');
+else
+    fprintf(fid, 'ymin=%f,\nymax=%f,\n',o.yrange(1),o.yrange(2));
+end
 
 if o.showLegend
     fprintf(fid, 'legend style={');
@@ -134,6 +124,13 @@ if o.showZeroline
     fprintf(fid, '%%zeroline\n\\addplot[black,line width=.5,forget plot] coordinates {(1,0)(%d,0)};\n',dd.ndat);
 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
+
 if ~isempty(o.shade)
     xTickLabels = strings(dd);
     x1 = find(strcmpi(date2string(o.shade(1)), xTickLabels));
@@ -141,17 +138,11 @@ if ~isempty(o.shade)
     assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ...
                         date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ...
                         'range of data selected.']);
-    fprintf(fid, ['%%shading\n\\addplot[area legend,solid,fill=%s,' ...
-                  'opacity=%f,draw=black,forget plot]\ntable[row sep=crcr]{\nx ' ...
-                  'y\\\\\n%d %d\\\\\n%d %d\\\\\n%d %d\\\\\n%d %d\\\\\n};\n'], ...
-            o.shadeColor, o.shadeOpacity, x1, ymin, x1, ymax, x2, ymax, x2, ymin);
-end
-
-for i=1:ne
-    o.series{i}.writeSeriesForGraph(fid, dd);
-    if o.showLegend
-        fprintf(fid, '\\addlegendentry{%s}\n', o.series{i}.getTexName());
-    end
+    fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
+                 'cs:%d,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
+                 'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n' ...
+                 '\\end{pgfonlayer}\n'], ...
+            o.shadeColor, o.shadeOpacity, x1, x2);
 end
 
 fprintf(fid, '\\end{axis}\n\\end{tikzpicture}\n');