Everyone, I would like to draw the region
\begin{align*}
x_1 + x_2 &\ge 3 \\
2x_1 - x_2 &\le 5 \\
-x_1 + 2x_2 &\le 3
\end{align*}
Here is my code to draw the region of inequality:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[htpb]
\centering
\label{fig:p3:c1}
\begin{tikzpicture}
\begin{axis}[axis on top,smooth,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=-1,ymax=6,xmin=-1,xmax=6,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
\addplot[thick,pattern=crosshatch,pattern color=blue!30!white,
domain=-10:4]{3-x} -| (axis cs:50, 50);
\addplot[thick,pattern=crosshatch dots,pattern color=green!60!white,
domain=-10:12]{-5+2*x} -| (axis cs: -50,50);
\addplot[thick,pattern=grid,pattern color=yellow,
domain=-10:10]{3/2+x/2} -| (axis cs: 20,0);
\addplot[very thick, domain=-10:10]{3-x};
\addplot[very thick, domain=-10:10]{-5+2*x};
\addplot[very thick, domain=-10:10]{3/2+x/2};
\end{axis}
\end{tikzpicture}
\caption{Problem 4, Part A}
\end{figure}
\end{document}
This code have several problems.
In order not let pattern to cover the line, I draw every function twice. Can we draw the pattern just before draw all the line?
The grid overlap show before the line. (I also want to let axis on the top)
How to fill the region above/under a curve/line? As you can see, I just use a very ugly way. It will draw unnecessary line (now it is overlapped with axis) and it is not beautiful. I need to modify the coordinate every time I change other things. Any better method?