1

I would like to know how to draw the "less than" or "greater than" lines in a tikz graph.

i found this nice graph but am unable to draw the "zebra-lines". Is there a package for this?

shown what i want

For my plots I'm currently using pgfplot

\documentclass[12pt, a4]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document} \begin{figure}[h] \begin{tikzpicture} \begin{axis}[ axis x line=center, axis y line=center, xlabel=$x_1$, ylabel=$x_2$, xmin=-1, ymin=-1, xmax=8, ymax=15, xtick={-1,0,1,2,...,8}, ytick={0,2,3,4,6,8,10,12} ] \addplot[mark=none, domain=-1:8] {-4x + 8}; % -4x_1 -x_2 <= -8 \addplot[mark=none, domain=-1:8] {x + 3}; \addplot[mark=none, domain=-1:8] {2}; \addplot[mark=none, domain=-1:8] {-2x + 12}; \addplot[fill=blue!20,draw=blue]coordinates{(1,4)(3,6)(5,2)(1.5,2)}; \drawred, ->--(3,9); \node[label={180:{(3,6)}}, circle, fill=red, inner sep=2pt] at (axis cs:3,6) {};

    \end{axis}
\end{tikzpicture}

\end{figure}

\end{document}

which looks like this:

current situation

Isitar
  • 141
  • 1
    See if https://tex.stackexchange.com/questions/188717/decorating-a-paths-edge-with-a-hatch-pattern-in-tikz or https://tex.stackexchange.com/questions/419533/tikz-how-to-draw-a-pattern-at-the-border-of-a-tikz-path helps. – Torbjørn T. Sep 19 '20 at 17:35
  • thank you very much !

    the decorations worked perfectly: \addplot[mark=none, domain=-1:8, decoration={border,segment length=1mm,amplitude=2mm,angle=-135}, postaction={decorate,draw} ] {-2*x + 12};

    – Isitar Sep 19 '20 at 18:00

1 Answers1

1

I answer my own question thanks to the comment from torbjørn

This can be achieved with decorations.

to simplify different colors for the decoration & the line itself, I created these two helper methods

\newcommand{\lightgray}{black!30}
\newcommand{\addPlotLDown}[1]{
    \addplot[mark=none, domain=-1:8, color=\lightgray,
        decoration={border,segment length=1mm,amplitude=1.5mm,angle=-135},
        postaction={decorate}
    ] {#1};
    \addplot[mark=none, domain=-1:8] {#1};
}
\newcommand{\addPlotRUp}[1]{
    \addplot[mark=none, domain=-1:8, color=\lightgray,
        decoration={border,segment length=1mm,amplitude=1.5mm,angle=135},
        postaction={decorate}
    ] {#1};
    \addplot[mark=none, domain=-1:8] {#1};
}

the plot itself can then be drawn with these instructions:

\begin{figure}[h]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            axis x line=center,
            axis y line=center,
            xlabel=$x_1$,
            ylabel=$x_2$,
            xmin=-1,
            ymin=-1,
            xmax=8,
            ymax=15,
            xtick={-1,0,1,2,...,8},
            ytick={0,2,3,4,6,8,10,12}
        ]
    \addplot[fill=blue!20,draw=none]coordinates{(1,4)(3,6)(5,2)(1.5,2)};

    \addPlotRUp{-4*x + 8};
    \addPlotLDown {x+3}
    \addPlotRUp{2}
    \addPlotLDown{-2*x+12}

    \addplot[fill=none,draw=blue]coordinates{(1,4)(3,6)(5,2)(1.5,2)};
    \draw[red, -&gt;](3,6)--(3,9);
    \node[label={180:{(3,6)}}, circle, fill=red, inner sep=2pt] at (axis cs:3,6) {};

    \end{axis}
\end{tikzpicture}

\end{figure}

which results in the following graph solution

Isitar
  • 141