2

The following code does not produce the figure expected.

    \documentclass{standalone}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.8}
    \usepackage{amssymb,amsmath}
    \definecolor{prune}{rgb}{0.6,0.00,0.48}
    \definecolor{bleu}{rgb}{0.1,0.05,0.5}
    \begin{document}
    \begin{tikzpicture}
    \begin{axis}
      [restrict x to domain=-4:8, xmax=8, xmin=-4,
      restrict y to domain=-5:6, ymax=6, ymin=-5,
      x=0.5cm,
      y=0.5cm,
      axis x line=middle,
      axis y line=middle, 
      line width = 0.4mm,
      xtick=\empty,
      ytick=\empty,
      samples=1000,
      >=stealth,
      compat=1.8,
       ]
     \addplot[line width=1,smooth,domain=-4:8,bleu] {-.25*x^2+x+3} ;
     \draw[dashed,thin,prune] (2,-5)--(2,6) ;
     \draw[dashed,thin,prune] (0,4) --(2,4) ; 
     \node[below left] (O) at (0,0) {O} ; 
     \node[above right,prune] (S) at (2,4) {S}; 
     \node[left,prune] (text1) at (0,4) {$f\left(-\dfrac{b}{2a}\right)$} ;
     \node[below right,prune] (text2) at (2,0) {$-\dfrac{b}{2a}$} ;    
     \end{axis}
     \end{tikzpicture}
     \end{document}

Here is the figure I want :

enter image description here

  • Edit the image in code ... – juanuni May 18 '15 at 16:20
  • @ juanuni What do you mean ? – Fabrice May 18 '15 at 16:34
3

You need to add axis cs: (axis coordinates) before each coordinate like (axis cs:0,0), because the axis coordinates are different from the actual ones.

I changed your code slightly, and enlarged the maximum axis coordinates because your plot gets cut otherwise. Also, there's no need to specify the compatibility in two places. The first one was the right one.

I also switched to the arrows.meta library (arrows seems to be deprecated), while bending is for properly placing the arrow tip on the curve.

Output

figure 1

Code

\documentclass[margin=10pt]{standalone}
\usepackage{amssymb,amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\usetikzlibrary{arrows.meta,bending}

\definecolor{prune}{rgb}{0.6,0.00,0.48}
\definecolor{bleu}{rgb}{0.1,0.05,0.5}

\tikzset{
    mye/.style={dashed, thin, prune}
}

\begin{document}
\begin{tikzpicture}[>={Stealth}]
\begin{axis}[
    xmin=-4, xmax=10,
    ymin=-6, ymax=6, 
    enlarge x limits=1,
    enlarge y limits=0.2,
    x=0.5cm,
    y=0.5cm,
    axis x line=middle,
    axis y line=middle, 
    line width = 0.4mm,
    xtick=\empty,
    ytick=\empty,
    samples=1000
]

\addplot[line width=1,smooth,domain=-4:8,bleu,-{<[flex=0.5]}] {-.25*x^2+x+3};
\draw[mye] (axis cs:2,-5) -- (axis cs:2,6);
\draw[mye] (axis cs:0,4) -- (axis cs:2,4); 
\node[anchor=north east] (O) at (axis cs:0,0) {O}; 
\node[above right,prune] (S) at (axis cs:2,4) {S}; 
\node[left,prune] (text1) at (axis cs:0,4) {$f\left(-\dfrac{b}{2a}\right)$};
\node[below right,prune] (text2) at (axis cs:2,0) {$-\dfrac{b}{2a}$};   
\end{axis}
\end{tikzpicture}
\end{document}
  • @ Alenanno Sorry for the late response! Thank you very much, I have now to place the basis vectors and labels x and y. – Fabrice May 19 '15 at 16:09
1

In online compiler appears error with compat=1.8. In your code compat=1.8 appears in \pgfplotsset and like option in axis environment. I delete that and produce this

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amssymb,amsmath}
\definecolor{prune}{rgb}{0.6,0.00,0.48}
\definecolor{bleu}{rgb}{0.1,0.05,0.5}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  [restrict x to domain=-4:8, xmax=8, xmin=-4,
  restrict y to domain=-5:6, ymax=6, ymin=-5,
  x=0.5cm,
  y=0.5cm,
  axis x line=middle,
  axis y line=middle, 
  line width = 0.4mm,
  xtick=\empty,
  ytick=\empty,
  samples=1000,
  >=stealth
   ]
 \addplot[line width=1,smooth,domain=-4:8,blue] {-.25*x^2+x+3} ;
 \draw[dashed,thin,prune] (2,-5)--(2,6) ;
 \draw[dashed,thin,prune] (0,4) --(2,4) ; 
 \node[below left] (O) at (0,0) {O} ; 
 \node[above right,prune] (S) at (2,4) {S}; 
 \node[left,prune] (text1) at (0,4) {$f\left(-\dfrac{b}{2a}\right)$} ;
 \node[below right,prune] (text2) at (2,0) {$-\dfrac{b}{2a}$} ;    
 \end{axis}
 \end{tikzpicture}
 \end{document}

enter image description here

What is bad? The letter S? ... in your code appears like node.

  • @ juanuni I added the expected figure (made with PSTricks). How to add a larger image on the forum ? – Fabrice May 18 '15 at 17:00
  • @Fabrice try with \addplot instead \draw – juanuni May 18 '15 at 17:06
  • @ juanuni This does not work, but thank you for the attention paid to the question. – Fabrice May 19 '15 at 16:13
  • Oh, is not for your last picture in your question. Alenano did you a response before ... – juanuni May 20 '15 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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