I need to show a plot whose background is painted in different colors at certain X intervals. I tried fill but it paints over the grid and the interval markers on X and Y axis. I know I can draw them again, but I was hoping it would be possible to define the draw order and draw the fill before everything else (as it is background).
Also, I have a lot of intervals, so is there a way to paint them automatically following a pattern (instead of copy-pasting code for each interval)?
Ex:
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=80,
ymin=0, ymax=50,
ymajorgrids=true,
grid style=dashed,
]
\fill[red] (0,0) rectangle (20,50);
\fill[green] (20,0) rectangle (40,50);
\fill[red] (40,0) rectangle (60,50);
\fill[green] (60,0) rectangle (80,50);
\addplot[color=blue] coordinates {(0, 34.000000) (20, 40.000000) (40, 28.000000) (60, 37.000000) (80, 45.000000)};
\end{axis}
\end{tikzpicture}
