5

Hi I am trying to plot the following tikz code:

\def\tr{0.1}
\def\ts{0.6}
\def\al{1.3}
\def\n{1.6}
\def\I{0.3506}
\def\ti{0.4071}
\def\S{-0.1340}
\def\Sangle{-42}
\def\f1{0.8}

\begin{tikzpicture}[domain=-3:5, xscale=1, yscale=5, >=latex]
  \draw[very thin,color=gray!30] (-3,0)
    grid[xstep=0.5, ystep=0.1] (5,0.7);
  \draw[->, line width=1pt] (-3,0) -- (5.25,0)
    node[below] {$\log(\psi)$};
  \draw[->, line width=1pt] (-3,0) -- (-3,0.75)
    node[left] {$U(\psi)$};
  \draw[color=green!30!black, thick, smooth]
    plot[id=x, domain=-3:5]
    function{\tr+(\ts-\tr)/(1+(\al*exp(x))**\n)**(1-1/\n)};
  \node[left] (tr) at (-3,\tr) {$U_r$};
  \node[left] (ts) at (-3,\ts) {$U_s$};
  \draw[dashed] (\I,0) node[below] {$I$} -- (\I,\ti) -- (-3,\ti)
    node[left] {$U_i$};
  \draw[color=green!30!black, dashed]
    plot[id=x, domain=-1.5:3]
    function{\ti+\S*(x-\I)};
  \draw[|<->|] (\I,\ti)++(1,0) arc (0:\Sangle:0.8 and 0.15);
  \path (\I,\ti)++(0.5*1.5\Sangle/8:1)
    node[right=-1pt] {$\tan^{-1}(S)$};
  \node[anchor=base] (vg) at (1,0.8)
    {$U(\psi) = U_r+\displaystyle\frac{U_s-U_r}{(1+(\alpha\psi)^n)^m}$};
\end{tikzpicture}

But for some reason, the function is not plotted I just get this:

enter image description here

Could someone tell me what I am doing wrong?

  • 1
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. Also, if you are trying to do a graph you should consider pgfplots which is specifically designed for graphs. – Peter Grill Mar 24 '18 at 3:45
  • 1
    As marmot indicates, when you do plot function TikZ actually outsources the computation of the function values to Gnuplot. So you a) need to have Gnuplot installed properly, and b) you need to run pdflatex with --shell-escape in order to allow pdflatex to execute other programs. – Torbjørn T. Mar 24 '18 at 9:00
11

Yes, most likely you do not have the relevant software (gnuplot?) installed. But you don't need it, you can draw the functions with TikZ only.

\documentclass[tikz]{standalone}
\def\TR{0.1}
\def\TS{0.6}
\def\al{1.3}
\def\n{1.6}
\def\I{0.3506}
\def\ti{0.4071}
\def\S{-0.1340}
\def\Sangle{-42}
\def\fone{0.8}
\begin{document}
\begin{tikzpicture}[xscale=1, yscale=5, >=latex]
  \draw[very thin,color=gray!30] (-3,0)
    grid[xstep=0.5, ystep=0.1] (5,0.7);
  \draw[->, line width=1pt] (-3,0) -- (5.25,0)
    node[below] {$\log(\psi)$};
  \draw[->, line width=1pt] (-3,0) -- (-3,0.75)
    node[left] {$U(\psi)$};
  \draw[color=green!30!black, thick, smooth]
    plot[id=x, domain=-3:5]
    ({\x},{\TR+(\TS-\TR)/(1+(\al*exp(\x))^\n)^(1-1/\n)});
  \node[left] (tr) at (-3,\TR) {$U_r$};
  \node[left] (ts) at (-3,\TS) {$U_s$};
  \draw[dashed] (\I,0) node[below] {$I$} -- (\I,\ti) -- (-3,\ti)
    node[left] {$U_i$};
  \draw[color=green!30!black, dashed]
    plot[id=x, domain=-1.5:3]
    ({\x},{\ti+\S*(\x-\I)});
  \draw[|<->|] (\I,\ti)++(1,0) arc (0:\Sangle:0.8 and 0.15);
  \path (\I,\ti)++(0.5*1.5\Sangle/8:1)
    node[right=-1pt] {$\tan^{-1}(S)$};
  \node[anchor=base] (vg) at (1,0.8)
    {$U(\psi) = U_r+\displaystyle\frac{U_s-U_r}{(1+(\alpha\psi)^n)^m}$};
\end{tikzpicture}
\end{document}
\endinput

enter image description here

Note that I used the opportunity to give some of your variables a safer name, e.g. \tr is really dangerous since it stands for trace, and so on. Note also that def\f1{0.8} does not do what you probably want, LaTeX does not accept numbers in macro names.

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.