I have a problem like the one in this question concerning a tikz drawing but for a pgfplots plot. I want to create a plot that has one region filled without opacity and a neighboring one filled with opacity. The transparent region should be coated by a solid line. I managed to get pretty much what I want with this code:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepackage{pgfplotstable} % For \pgfplotstableread
\usepgfplotslibrary{external}
\tikzexternalize
\usepackage{filecontents}
\begin{filecontents}{total.dos}
0 0 0 0 0
1 2 -2 2 -2
2 4 -4 4 -4
3 2 -2 2 -2
4 0 0 0 0
5 1 -1 0 0
6 2 -2 0 0
7 1 -1 0 0
8 0 0 0 0
THIS WAS: TOTAL
\end{filecontents}
\pgfplotstableread[comment chars={T}]{total.dos}\total
\begin{document}
% Set a filename for the next tikzpicture.
\tikzsetnextfilename{total_dos}
\begin{tikzpicture}
\begin{axis}[ymax=7, ymin=-7, xlabel={Energy [eV]}, ylabel={Intensity}, legend pos=north east]
\addplot [restrict x to domain=4:8, no markers, draw=red, fill=red, fill opacity=0.3] table [x=0, y expr=\thisrowno{2} - \thisrowno{4}] {\total}; \addlegendentry{$2-4$}
\addplot [restrict x to domain=4:8, no markers, draw=blue, fill=blue, fill opacity=0.3] table [x=0, y expr=\thisrowno{1} - \thisrowno{3}] {\total}; \addlegendentry{$1-3$}
\addplot [restrict x to domain=0:4, no markers, draw=blue , fill=blue] table [x=0, y=3] {\total}; \addlegendentry{$3$}
\addplot [restrict x to domain=0:4, no markers, draw=red, fill=red] table [x=0, y=4] {\total}; \addlegendentry{$4$}
\end{axis}
\end{tikzpicture}
\end{document}
This gives the following picture:

The problem is the intersections of the coating lines' ends (those that come from the draw=<color> options). They are not smooth, but look like this:

My question: How can I get these things smooth?
Side note: I know that using the option draw=none gives the behaviour I want, but then I have no line surrounding the transparent region.
Edit:
I have stumbled upon something interesting: Adobe Acrobat X and SumatraPDF seem to handle the plots slightly differently. Acrobat cuts off the parts of the rightmost line endings that loom beyond the plotting domain (I don't know a better word for it) while SumatraPDF doesn't. Interestingly, this doesn't happen for the line endings on the left or in the middle (see picture above, which was made with Acrobat).
I'm not sure why this is so and whether it affects the possible solutions to my problems. Maybe this is an issue worth adressing in a different question? Or is this a mere PDF viewer question which shouldn't be asked here?






line cap=roundas an option to the\addplotcommands do what you want? – Jake Jan 23 '12 at 00:19triangle 90 caparrow fromarrowslibrary can increase the blend feel. – percusse Jan 23 '12 at 00:58tikzand couldn't get your suggestion to work. I loaded\usetikzlibrary{arrows}in the preamble and tried to use the optionline cap=triangle 90 capafteraddplotbut that didn't work. Was this all wrong? I expect it to look similar toline cap=round. But those are just workarounds. Will it be possible to make the lines really blend like in thetikzquestion I linked? – Philipp Jan 23 '12 at 01:32tikzI hadn't realized that this might be such a difficult question. Youthful naivety is wonderful, isn't it ;) – Philipp Jan 23 '12 at 01:54tikzandpgfplotsin general. – Philipp Mar 31 '13 at 01:50