3

I' trying to shade an upper contour set. As I do it in two steps (one for the curved part of the set, another for the straight one) I get a bit of an overlap between the two that results in a darker vertical line that shouldn't be there.![enter image description here

My guess is that the darker line appears as a consequence of the overlap of the two regions I'm trying to fill rather than it being a rendering error. I've tried reducing a bit the size of the second region (the rectangle of the fill instruction) but then I get a white (rather than the dark) line between the regions. I believe I should define the path setZ so that I goes all the way to the end of the axis, but I do not know how to do it. Here is my MWE

\documentclass{article}
\usepackage{tikz,pgfplots}

\pgfplotsset{compat = newest}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{figure}
   \begin{tikzpicture}
     \begin{axis}[ 
       ticks=none, 
       axis x line=bottom,
       axis y line=left,
       xmin=0,xmax=16,
       ymin=0,ymax=16,
       ]
     \addplot[
       name path=setZ,
       ] table {
       4.68 12
       5.68 9
       6.68 7
       7.68 6
       10.16 5
       };
    \path [name path=axiss] (4.68,16) -- (10.16,16);
    \addplot[gray,opacity=0.2] fill between [
       of=setZ and axiss];
    \fill[gray,opacity=0.2] (10.16,5)--(16,5)--(16,16)--(10.16,16);
    \end{axis}
   \end{tikzpicture}
\end{figure}

\end{document}

Edit: A possibility is to create a last point in the path so that it reaches the end of the pictured axis, e.g.

     \addplot[white,name path=setZ] table {
        4.68 12
        5.68 9
        6.68 7
        7.68 6
        10.16 5
        16 5
        };

before the plot itself and modify the definition of axiss accordingly. However, I have my data stored in a file and I'd rather not have two almost identical, separate files.

4
  • Which pdf viewer do you use? The result looks fine in texstudio and mac perview.app i.stack.imgur.com/WRDfx.png Dec 27, 2022 at 20:27
  • @samcarter_is_at_topanswers.xyz I've used the built in previewer in TexWorks and Acrobat. The capture is from Acrobat
    – Patricio
    Dec 27, 2022 at 20:36
  • 1
    I can reproduce the issue with adobe reader, so I'd guess a viewer issue. You can avoid it by using \fill[gray!20] (e.g. no opacity, but using a suitable colour instead) Dec 27, 2022 at 20:41
  • @samcarter_is_at_topanswers.xyz I thought it was due to the fact that both regions included $x=10.16$ and the overlap was causing the darker color.
    – Patricio
    Dec 27, 2022 at 20:55

1 Answer 1

4

To avoid viewer artefacts, you should fill the whole area with one fill. There is no need to use fillbetween for this simple area.

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
4.68 12
5.68 9
6.68 7
7.68 6
10.16 5
}\loadedtable
\begin{axis}[ 
axis lines=center,
ticks=none, 
xmin=0, xmax=16,
ymin=0, ymax=16,
]
\addplot[draw=none, fill=gray!20] table {\loadedtable} -| (current axis.north east) -| cycle;
\addplot[mark=none] table {\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}

Graph with curve and filled area

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .