填充 tikzpicture 中的区域

填充 tikzpicture 中的区域

有人能帮忙吗?填充区域不对称。目标是对称。

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4.0,0.0) -- (4.0,0.0);
\foreach \x in {-4.0,-3.0,-2.0,-1.0,1.0,2.0,3.0}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.0,-0.5) -- (0.0,5.5);
\foreach \y in {,1.0,2.0,3.0,4.0,5.0}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.0,-0.5) rectangle (4.0,5.5);
\draw[color=zzttqq,fill=zzttqq,fill opacity=0.1, smooth,samples=50,domain=-2.0:2.0] plot(\x,{(\x/2.0)^(4.0)-\x^(2.0)+5.0}) -- (2.0,0.0) -- (-2.0,0.0) -- cycle;
\draw[smooth,samples=100,domain=-4.0:4.0] plot(\x,{((\x)/2.0)^(4.0)-(\x)^(2.0)+5.0});
\begin{scriptsize}
\draw[color=black] (-4.140000000000001,6.140000000000001) node {$f$};
\end{scriptsize}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

Jake 的评论应该已经解决了您的问题。这是向您展示另一种方法。

这可以做到,pgfplots而且非常容易。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11,width=4in}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis lines = middle,
  xmin=-5,
  xmax=5,
  ymin=0,
  ymax=6,
  xlabel=$t$,
  ylabel=$v$,
  xtick={-4,...,4},
  ytick={1,...,5},
]
\addplot[draw=zzttqq,samples=100,domain=-2.0:2.0,fill=zzttqq,fill opacity=0.1] {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}}\closedcycle;
\addplot[blue,thick,samples=100,domain=-4.0:4.0] {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

这使用了fillbetween以下库pgfplots

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11,width=4in}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis lines = middle,
  xmin=-5,
  xmax=5,
  ymin=0,
  ymax=6,
  xlabel=$t$,
  ylabel=$v$,
  xtick={-4,...,4},
  ytick={1,...,5},
]
\addplot[draw=none,samples=100,domain=-4.0:4.0,name path =A] {0}\closedcycle;
\addplot[blue,thick,samples=100,domain=-4.0:4.0,name path=B]
                                              {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}};
\addplot[zzttqq,fill opacity=0.1] fill between[of=A and B,soft clip={domain=-2:2},];
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容