填充两个图之间

填充两个图之间

我画了两条线,例如,

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\draw [->] (-5,0) -- (5,0) node [above left]  {$x$} ;
\draw [->] (0,-5) -- (0,5) node [below right] {$y$} ;
\draw[dashed,domain=0:5] plot (\x, -\x) node [right] at (4,-3) {$y=x$};
\draw[domain=-5:0] plot (\x, \x);


\end{tikzpicture}
\end{document}

在此处输入图片描述

我怎样才能填充这两条线之间的区域并在其中写一些内容?

答案1

您可以使用以下方法再次绘制线条\fill

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \fill[domain=0:5,orange] plot (\x, -\x) -- (0,-5);
  \fill[domain=-5:0,orange] plot (\x, \x) -- (0,-5);

  \draw[dashed,domain=0:5] plot (\x, -\x) node [right] at (4,-3) {$y=x$};
  \draw[domain=-5:0] plot (\x, \x);

  \draw [->] (-5,0) -- (5,0) node [above left]  {$x$} ;
  \draw [->] (0,-5) -- (0,5) node [below right] {$y$} ;

  \node at (1,-3) {some text}; 
\end{tikzpicture}

\end{document}

答案2

PSTricks 解决方案:

\documentclass{article}

\usepackage{pst-plot}

\begin{document}

\def\size{5} % Change according to needs.
\begin{pspicture}(-\size.2,-\size.1)(\size.7,\size.7)
  \pscustom[
    linestyle = none,
    fillstyle = solid,
    fillcolor = lightgray
  ]{
     \psline(-\size,-\size)(0,0)(\size,-\size)
   }
  \psline(-\size,-\size)(0,0)
  \psline[
    linestyle = dashed
  ](0,0)(\size,-\size)
  \psaxes{->}(0,0)(-\size,-\size)(\size.3,\size.3)[$x$,0][$y$,90]
  \rput(-3,-2){$y = x$}
\end{pspicture}

\end{document}

输出

您所要做的就是选择值\size,然后绘图就会自动调整。

相关内容