Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Can somebody help? The fill area is not symmetric. The goal is to be symmetric.

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

enter image description here

share|improve this question
1  
Welcome to TeX.SX! No need to sign with your name since it automatically appears in the lower right corner of your post. –  Claudio Fiandrino Sep 4 at 13:08
1  
You need to use (\x)^(2.0) instead of \x^(2.0). See How can I work around this TikZ bug: (\x)^2 and \x^2 produce different results in TikZ plot? –  Jake Sep 4 at 13:11

1 Answer 1

Jake's comment should have solved your problem. This is to show you another method.

This can be done with pgfplots and it is very easy.

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

enter image description here

This uses fillbetween library of 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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.