2

I would like to color the region above the parabola, I found some suggestions here, but I couldn't adapt. My code is

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset
 {every pin/.style = {pin edge = {<-}}, 
  > = stealth, 
  flow/.style = 
   {decoration = {markings, mark=at position #1 with {\arrow{>}}},
    postaction = {decorate}
   },
  flow/.default = 0.5,   
  main/.style = {line width=1pt}
 }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round]

\draw [main,->] (0,-0.3) -- (0,5)
node [label={[above]$y$}] {}; \draw [main,->] (-5,0) -- (5,0)
node [label={[right,yshift=-0.5ex]$x$}] {}; \draw [main, domain=-4:4,color=red] plot (\x, {0.25\x\x});

\end{tikzpicture} \end{document}

I didn't quite understand the codes. Later I would like to adapt it, because I want to generate other graphs, pinned above the graph, but only for positive x, painted above the graph but only for negative x, delimited by the graph and the vertical axis, etc ...

Bernard
  • 271,350
Mrcrg
  • 301

2 Answers2

4

Like this ?

screenshot

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset
 {every pin/.style = {pin edge = {<-}}, 
  > = stealth, 
  flow/.style = 
   {decoration = {markings, mark=at position #1 with {\arrow{>}}},
    postaction = {decorate}
   },
  flow/.default = 0.5,   
  main/.style = {line width=1pt}
 }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round]

\draw [main, domain=-4:4,color=red,fill=pink] plot (\x, {0.25\x\x}); \draw [main,->] (0,-0.3) -- (0,5)
node [label={[above]$y$}] {}; \draw [main,->] (-5,0) -- (5,0)
node [label={[right,yshift=-0.5ex]$x$}] {}; \end{tikzpicture} \end{document}

AndréC
  • 24,137
4

Question is very general and consequently unclear. In general, you can add to your basic diagram (consisting of axis and function curve) anything what you like. As an example see

\documentclass[tikz, margin=3.14159mm]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
                   > = stealth,
    every pin/.style = {pin edge = {<-}},
         flow/.style = {decoration = {markings, mark=at position #1 with {\arrow{>}}},
                        postaction = {decorate}
                        },
       flow/.default = 0.5,
         main/.style = {color=#1, line width=1pt, line cap=round, line join=round},
       main/.default = black
                }

\begin{document} \begin{tikzpicture} % shading function on negative domain % it is here that it is on background of image \fill [domain=-4:0, red!50] plot (\x, 0.25\x\x) |- cycle; % axis \draw [main,->] (0,-0.3) -- (0,5) node [above] {$y$}; \draw [main,->] (-5, 0) -- (5,0) node [right] {$x$}; % function + marked \draw [domain=-4:4, main=red, flow=0.75]
plot (\x, 0.25\x\x); % function + pin \coordinate[pin=above left:{$0.35x^2$}] (aux) at (3,0.2533); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517