Found the answer: pgfplots: prevent single plot from being listed in legend
I plot multiple things to one tikzpicture. Because the plotting order is important to me, to avoid overlaying of the hatch over plotted lines, I need to plot the hatches first. But now I don’t want to show the labels for all the hatch-plots (only for one). How can I leave / hide some plots form legend or do I need to use a secondary axe?
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepgflibrary{shapes.geometric}
\usetikzlibrary{patterns,arrows}
\begin{document}
\definecolor{plotrangecolor}{HTML}{D8D8D8} %{D8D8D8}
%%
%% https://tex.stackexchange.com/questions/29359/pgfplots-how-to-fill-the-area-under-a-curve-with-oblique-lines-hatching-as-a
%%
\tikzset{
hatch distance/.store in=\hatchdistance,
hatch distance=10pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=2pt
}
\makeatletter
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
\pgfusepath{stroke}
}
\begin{tikzpicture}
\begin{axis}[
xmin=1, xmax=15,
domain=1:15,
ymin=0, ymax=1.1,
no markers,
enlargelimits=false,
xlabel={x},
ylabel={y},
legend style={
cells={anchor=west},
legend pos=south east
}
]
\addplot[mark=none,
domain=2:4,
pattern=flexible hatch,
hatch distance=10pt,
hatch thickness=0.5pt,
draw=none,
pattern color=plotrangecolor,
area legend] {2} \closedcycle;
\addplot[mark=none,
domain=8:14,
pattern=flexible hatch,
hatch distance=10pt,
hatch thickness=0.5pt,
draw=none,
pattern color=plotrangecolor,
area legend] {2} \closedcycle;
\addplot coordinates {(1,1) (4,0.4) (7,0.6) (8,0.5) (14,0.2)};
\addplot coordinates {(1,0.2) (3,0.3) (5,0.7) (9,1) (14,0.5)};
\addlegendentry{ range }
\addlegendentry{ dont show this}
\addlegendentry{value 1}
\addlegendentry{value 2}
\end{axis}
\end{tikzpicture}
\end{document}

forget plot. This works for me:\addplot [black, forget plot, error bars/.cd, y dir=plus, y explicit]. But this doesn't work:\addplot [black, error bars/.cd, y dir=plus, y explicit, forget plot]. Notice the placement offorget plot. The error wasError: I do not know the key '/pgfplots/error bars/forget plot' and I am going to ignore it.I don't quite understand what the problem is, but I'll leave it here in case someone else bumps into the same issue. – Daniel Feb 20 '20 at 17:10error bars/.cdis the culprit there. After that all keys are assumed to be in theerror barsfamily, whichforget plotis not. Hence the message that/pgfplots/error bars/forget plotis not known, the "path" toforget plotis/pgfplots/forget plot. – Torbjørn T. Feb 20 '20 at 18:14