# Plot basic graphs (inequality)

I am beginner (and it is my fourth article here) and I am struggling with plotting some basic graphs. I found here some similar articles, but it did not help me. :( I want to plot graph, where is: y>= (1/x) (blue) and x<=0 (red). I thank you in advance for any help.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={ \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque, grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:5,0) -- (rel axis cs:5,5) -- (rel axis cs:0,5) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:5,5) -- (rel axis cs:5,0) -- (rel axis cs:0,0) \closedcycle}

\begin{document}

\begin{figure}[htpb]
\centering
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=middle,
axis y line=middle,
ymin=-3,ymax=5.99,xmin=-3,xmax=5.99,
xlabel=$x$, ylabel=$y$,grid=major
]
\addplot [draw=none, pattern=north west lines, pattern color=blue!40, domain=0.01:6]
{1/x} \drawge;
\addplot [draw=none, pattern=north west lines, pattern color=red!40, domain=-3:0]
{-3:0} \drawge;
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

• @PhelypeOleinik can I ask, how did you change it, please? – Euler Nov 30 '18 at 22:19
• You mean to format as code? You just select the code and click the {} button, like here: i.stack.imgur.com/EGnsG.png Any line that begins with four spaces is formatted as code. – Phelype Oleinik Nov 30 '18 at 22:24

You make your own life a bit complicated by running all these things in the beginning. Assuming you will use them somewhere, I left them in, and propose

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={ \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque, grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:5,0) -- (rel axis cs:5,5) -- (rel axis cs:0,5) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:5,5) -- (rel axis cs:5,0) -- (rel axis cs:0,0) \closedcycle}

\begin{document}

\begin{figure}[htpb]
\centering
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=middle,
axis y line=middle,
ymin=-3,ymax=5.99,xmin=-3,xmax=5.99,
xlabel=$x$, ylabel=$y$,grid=major,samples=101
]
\addplot [draw=none, pattern=north west lines, pattern color=blue!40, domain=0.01:6]
{1/x} \drawge;
\addplot [pattern=north west lines, pattern color=red!40] fill between [of=top and bottom,soft  clip={domain=-3:0}];
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={ \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque, grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:5,0) -- (rel axis cs:5,5) -- (rel axis cs:0,5) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:5,5) -- (rel axis cs:5,0) -- (rel axis cs:0,0) \closedcycle}

\begin{document}

\begin{figure}[htpb]
\centering
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=middle,
axis y line=middle,
ymin=-3,ymax=5.99,xmin=-3,xmax=5.99,
xlabel=$x$, ylabel=$y$,grid=major,samples=101
]
%             \addplot [draw=none, pattern=north west lines, pattern color=blue!40, domain=0.01:6]
%             {1/x};