Q:

filling plot region changes error bars of another plot

I have the following plot:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{pgfplotstable}
\usepgfplotslibrary{fillbetween}
\pgfplotstableread{
  X Xminus Xplus
  1.13 0.1 0.2
  1.14 0.02 0.7
  1.145 0.23 0.23
}\data
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval

\begin{document}
\begin{tikzpicture}[trim axis left,trim axis right]
    \begin{axis}[y=-\baselineskip,
        scale only axis,
        width             = 6.5cm,
        enlarge y limits  = {abs=0.5},
        axis y line*      = middle,
        y axis line style = dashed,
        ytick             = \empty,
        axis x line*      = bottom
      ]
      \addplot+[mark=none, update limits=false,color = black] coordinates {(1.1, -1) (1.1, \numberofrows-0.5)};
      \addplot+[mark=none, update limits=false, dashed, color = black,name path=errmin] coordinates {(1.05, -1) (1.05, \numberofrows-0.5)};
      \addplot+[mark=none, update limits=false, dashed, color=black,name path=errmax] coordinates {(1.15, -1) (1.15, \numberofrows-0.5)};
      % \addplot+[mark=none, update limits=false, fill=black!10] fill between [of=errmin and errmax];
      \addplot+[only marks, blue, thick, mark=*, solid, error bars/.cd,x dir=both, x explicit]
        table [x=X,y expr=\coordindex,x error minus=Xminus, x error plus=Xplus]{\data};
      \end{axis}
    \end{tikzpicture}

\end{document}

which gives me the expected result:

When I then uncomment the line to fill the region between the dashed lines
      \addplot+[mark=none, update limits=false, fill=black!10] fill between [of=errmin and errmax];

I get strange error markers (actually the bars are okay, but the markers are shifted in a strange way)

What am I doing wrong here? I am unable to figure out what is the problem here.. Is it expected behaviour?

A:

The mess is caused by trim axis right which (in this case) isn't needed/doesn't change the output if present or not.
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        compat=1.16,
        % (added this style to shorten later calls)
        vertical lines style/.style={
            mark=none,
            update limits=false,
            color=black,
        },
    }
    \pgfplotstableread{
        X       Xminus  Xplus
        1.13    0.1     0.2
        1.14    0.02    0.7
        1.145   0.23    0.23
    }\data
    \pgfplotstablegetrowsof{\data}
    \let\numberofrows=\pgfplotsretval
\begin{document}
\begin{tikzpicture}[
%    trim axis left,
%    trim axis right    % <-- this causes the mess
]
    \begin{axis}[
        y=-\baselineskip,
        scale only axis,
        width=6.5cm,
        enlarge y limits={abs=0.5},
        axis y line*= middle,
        y axis line style=dashed,
        ytick=\empty,
        axis x line*=bottom,
        axis on top,    % <-- (added, so the x-axis is in front of the fill between)
    ]
        \addplot [vertical lines style]
            coordinates {(1.1, -1) (1.1, \numberofrows-0.5)};
        \addplot [vertical lines style,dashed,name path=errmin]
            coordinates {(1.05, -1) (1.05, \numberofrows-0.5)};
        \addplot [vertical lines style,dashed,name path=errmax]
            coordinates {(1.15, -1) (1.15, \numberofrows-0.5)};
        \addplot [fill=black!10]
            fill between [of=errmin and errmax];
        \addplot+ [
            only marks,
            mark=*,
            error bars/.cd,
                x dir=both,
                x explicit,
        ] table [
            x=X,
            y expr=\coordindex,
            x error minus=Xminus,
            x error plus=Xplus,
        ] {\data};
    \end{axis}
\end{tikzpicture}
\end{document}

