在 tikz 圖中繪製“小於函數”

在 tikz 圖中繪製“小於函數”

我想知道如何在 tikz 圖中繪製“小於”或“大於”線。

我發現了這個漂亮的圖表,但無法繪製“斑馬線”。有這個包嗎?

顯示了我想要的

對於我的繪圖,我目前正在使用 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}

看起來像這樣:

現在的情況

答案1

感謝托比昂的評論,我回答了我自己的問題

這可以透過裝飾來實現。

為了簡化裝飾和線條本身的不同顏色,我創建了這兩種輔助方法

\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}

結果如下圖所示 解決方案

相關內容