在 tikz 图中绘制“小于函数”

在 tikz 图中绘制“小于函数”

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?

显示我想要的

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] {-4*x + 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] {-2*x + 12};
        \addplot[fill=blue!20,draw=blue]coordinates{(1,4)(3,6)(5,2)(1.5,2)};
        \draw[red, ->](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}

\end{document}

which looks like this:

现在的情况

答案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};
}

然后可以根据以下指令绘制图表本身:

\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, ->](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}

得到下图 解决方案

相关内容