I have modified the north east lines
pattern to accept a \LineSpace
option that sets the density of the pattern (see the question Can I control the density of a pattern in TikZ?). The code works very well but I can't modify the color of the pattern using the pattern color
option as I did before.
\documentclass{minimal}
\usepackage{pgfplots}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns}
\pgfdeclarepatternformonly[\LineSpace]{my north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\LineSpace}{\LineSpace}}{\pgfqpoint{\LineSpace}{\LineSpace}}%
{
\pgfsetlinewidth{0.4pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{\LineSpace + 0.1pt}}
\pgfusepath{stroke}
}
\newdimen\LineSpace
\tikzset{
line space/.code={\LineSpace=#1},
line space=3pt
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0, ymax=1,
xmin=-1, xmax=1]
\addplot[
pattern=my north east lines,
line space=8pt,
pattern color=green,
draw=black]
{x} \closedcycle;
\addplot[
pattern=north east lines,
pattern color=red,
draw=black]
{-x} \closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}