Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 opaque 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:

enter image description here

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:

enter image description here

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 opaque region.

share|improve this question
Would line cap=round as an option to the \addplot commands do what you want? – Jake Jan 23 '12 at 0:19
Also the triangle 90 cap arrow from arrows library can increase the blend feel. – percusse Jan 23 '12 at 0:58
@Jake: This option does improve the situation at the ends of the plot (though it's still not yet the optimum) but the intersection in the middle becomes worse than before. – Philipp Jan 23 '12 at 1:22
@percusse: I'm pretty new to tikz and couldn't get your suggestion to work. I loaded \usetikzlibrary{arrows} in the preamble and tried to use the option line cap=triangle 90 cap after addplot but that didn't work. Was this all wrong? I expect it to look similar to line cap=round. But those are just workarounds. Will it be possible to make the lines really blend like in the tikz question I linked? – Philipp Jan 23 '12 at 1:32
@Philipp: Doing this properly is really hard. Take a look at tex.stackexchange.com/questions/10980/… for some suggestions, but none of them are really the holy grail. – Jake Jan 23 '12 at 1:40
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.