# Shading the edge of inequalities in pgfplots

I teach College Algebra and need to create black and white handouts that show the solution to a system of inequalities. Normally, I would color the solution side of each inequality and note that the answer to all of the inequalities is the area where all of the colors overlap. In black and white, this is often done by hashing the solution side. As you add inequalities to the system, though, this can become a mess and hard to read (see for example How to draw the region of inequality?, or How to draw a region of inequality). What I want to do is hashing as shown in the example image below (not from my MWE) where the hash just follows the edge of the inequality rather than filling the entire region.

Here is an MWE that graphs two inequalities with pgfplots. How do I do the hashing along the edge? Note that I need the solution to work not just with linear inequalities, but graphs of parabolas and circles as well.

\documentclass[10pt]{article}

\usepackage{pgfplots}

\begin{document}

$\left\{ \begin{array}{l} y \le -3x + 6 \\ x > -2 \\ y \le 4 \\ \end{array} \right.$

\begin{tikzpicture}
\begin{axis}[
axis x line=center,  axis y line=center,
width=4in,           height=4in,
x axis line style={<->},
y axis line style={<->},
xmin=-10,   xmax=10,
ymin=-10,   ymax=10
]
\addplot [very thick,cyan!50!black,domain=-10:10] {6 - 3*x};
\addplot [very thick,cyan!50!black,domain=-10:10] {4};
\addplot [very thick,cyan!50!black,dashed] coordinates {(-2,-10) (-2,10)};
\end{axis}
\end{tikzpicture}
\end{document}


[UPDATE]

A good answer to this question was provided below. I also stumbled upon Decorating a path's edge with a hatch pattern in TikZ from which I was able to also develop the code below. I am posting it here for completeness with an example output image.

\documentclass[10pt]{article}

\usepackage{pgfplots}

\begin{document}

$\left\{ \begin{array}{l} y \le -3x + 6 \\ x > -2 \\ y \le 4 \\ y \ge x^2-4 \\ \end{array} \right.$

% Amplitude is the length of the hatching.
% Segment Length is the distance between the marks.
% Angle is the orientation of the hatches with +-90 being perpendicular.
\pgfplotsset{IneqStyleLess/.style = {%
decoration={border,segment length=1mm, amplitude=3mm,angle=-90},
postaction={decorate,draw},
thick,blue!50!white, draw opacity=0.5
}
}

\pgfplotsset{IneqStyleGtr/.style = {%
decoration={border,segment length=1mm, amplitude=3mm,angle=90},
postaction={decorate,draw},
thick,blue!50!white, draw opacity=0.5
}
}

\begin{tikzpicture}
\begin{axis}[
axis x line=center,  axis y line=center,
axis on top,
width=4in,           height=4in,
x axis line style={<->},
y axis line style={<->},
xmin=-10,   xmax=10,
ymin=-10,   ymax=10
]
domain=-10:10,
] {6 - 3*x};
thick,red!50!white,
domain=-10:10,
] {4};
thick,green!50!white] coordinates {(-2,-10) (-2,10)};
thick,purple!50!white,
domain=-10:10,
samples=100,
] {x*x-4};

\addplot [black,domain=-10:10] {6 - 3*x};
\addplot [black,dashed] coordinates {(-2,-10) (-2,10)};
\addplot [black,domain=-10:10, samples=100] {x*x-4};
\end{axis}
\end{tikzpicture}
\end{document}


• This is kind of ugly, but if I provide a point on the solution side of each inequality, is there a way to draw a set of short line (in other words clipped) segments from the inequality towards the point? The segments would not be parallel, but it might suffice if there is no better solution. – Christopher Donham Nov 29 '17 at 21:29
• I do not have much time at the moment bu you could try to decorate your plot with some zebras . This example (tex.stackexchange.com/questions/306230/…) may give you a starting point. – BambOo Nov 29 '17 at 22:37
• see, if tex.stackexchange.com/questions/352511 can help you. or explain in what your expectation differ from answer there. – Zarko Nov 30 '17 at 3:55
• Thank you for the reference, but as I show above in my example image, what I am looking for is not to fill in the entire solution region -- that I can do. What I want is to shade along the entire edge of each inequality. So if you look at my picture above, the red hashing goes along the entire line showing the region that is valid for red. Visibly, it also does not fill the entire half-plane (even though conceptually it does), but only shows for a short distance extending into the half-plane. – Christopher Donham Nov 30 '17 at 11:38
• Another way to do what I want might be to draw a band or strip that is filled with cross-hatching that goes along the path of the inequality, but use a clipping region to only draw the half plane that has the solution (or conversely, prevent drawing in the half plane that does not have the solution). Then overlay a line of the proper type (dotted or not). This is beyond my current ability with pgfplots, but might be possible for more knowledgeable user. – Christopher Donham Nov 30 '17 at 13:49

You can use a decoration similar to PGFplots: decorating plot but not legend, but when drawing lines, one has to use axis direction cs to for this to work. This has the drawback that the length of the lines are specified in axis units, so depending on the axis limits one has to scale the lines.

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings}
\tikzset{
region/.style={
postaction={decorate},
decoration={
markings,
mark=between positions 0 and 1 step 5mm with {%
% note that the values are in axis units
\draw [solid,thin] (axis direction cs:0,-0.1*#1) -- (axis direction cs:0,-1*#1);
}
},
/pgfplots/forget plot
},
region/.default=1
}

\begin{document}

$\begin{cases} y \le -3x + 6 \\ x > -2 \\ y \le 4 \\ \end{cases}$

\begin{tikzpicture}
\begin{axis}[
axis x line=center,  axis y line=center,
width=4in,           height=4in,
x axis line style={<->},
y axis line style={<->},
xmin=-10,   xmax=10,
ymin=-10,   ymax=10,
every axis plot/.append style={
very thick,
cyan!50!black,
domain=-10:10,
samples=2, % all you need for straight lines
}
]
\addplot [region] {6 - 3*x};