在 LaTex 中的 tikzpicture 中添加阴影?

在 LaTex 中的 tikzpicture 中添加阴影?

在此处输入图片描述我是第一次使用 LaTex 绘图,我无论如何也搞不清楚如何在“无法通过 SNAP 实现...”箭头指向的水平线上添加阴影。如能得到任何帮助我将不胜感激。

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{relsize}
\begin{document}
\begin{figure}

\tikzset{fontscale/.style = {font=\relsize{#1}}
    }

\begin{tikzpicture}[thick,font=\sffamily,scale=1.25]

\draw [thick] (0,0) -- (8,0);
\draw [thick] (0,0) -- (0,6);
\node [right] at (8.2,-.15) {\large $Food$};
\node [above] at (0,6) {\large $Other \, Goods $};

\draw [thick, red] (3.4,2.5) -- (7.5,0)node[above right]{\large $BC \, 2$};
\draw[thick] (3.4,2.5) -- (0,4.7);
\node [rectangle, draw] at (5,5){\begin{tabular}{c} Unattainable \\ with SNAP and \\ Purchase Requirement \end{tabular}};
\draw [->,>=stealth] (5,3.6) -- (2,3);


\draw[dashed](3.4,2.5)--(0,2.5);
\draw [thick, blue] (0,3.4) -- (5.4,0)node[above right]{\large $BC \, 1$};

\node [left] at (0,3.4) {\large $\frac{y}{P_G}$};
%Horz BC Line

\node[below] at (5.4,0){\large $\frac{y}{P_F}$};
\node[below] at (7.5,0){\large $\frac{y+FS}{P_F}$};

%Labels

\node [left] at (0,3){ Purchase  Requirement};
\draw [->,>=stealth] (-0.5,2.8) -- (.5,2.75);
\end{tikzpicture}
\caption{Consumer Choice Model with Purchase Requirement}
\end{figure}
\end{document}

我想要阴影所在的位置!

答案1

建议:使用\pgfplots\usepgfplotslibrary{fillbetween}

\documentclass[border=2cm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}

    \begin{tikzpicture}
        \begin{axis}[
            samples=1000,
            xlabel=Foods,
            xtick=\empty,
            ytick=\empty,
            ylabel=other goods,
            xmin=-1,xmax=10,
            ymin=-1,ymax=10,
            axis lines=middle,
            enlargelimits={abs=0.5},
            ]
            \addplot[smooth,domain = 0:5,name path = A,black]{-x+8};
            \addplot[smooth,domain = 5:8,name path = B,red]{-x+8} node[yshift=0.5cm]{BC2};
            \addplot[smooth,domain = 0:5,name path = C,blue]{-x+5}node[yshift=0.5cm] {BC1};
            \addplot[dashed,domain = 0:5,name path = D]{3};
            \addplot[gray,opacity=0.2] fill between[of=A and C,soft clip={domain=2:2}]; %fill up space
            \addplot[gray,opacity=0.2] fill between[of=A and D,soft clip={domain=2:5}]; %fill up space
            
            %nodes of formula
            \node[yshift=-0.4cm] at (axis cs:5,0) {\large $\frac{y}{P_F}$};
            \node[yshift=-0.4cm] at (axis cs:8,0) {\large $\frac{y+FS}{P_F}$};
            \node[xshift=-0.4cm] at (axis cs:0,5) {\large $\frac{y}{P_G}$};
            
        \end{axis}

        %your Boxes
        \node [rectangle, draw] at (6,4.5){\begin{tabular}{c} Unattainable \\ with SNAP and \\ Purchase Requirement \end{tabular}};
        \draw [->,>=stealth] (5,3.6) -- (2,3);
        
        \node [left] at (0,2.75){ Purchase  Requirement};
        \draw [->,>=stealth] (-0.5,2.6) -- (1.2,2.4);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容