0

I'm trying to use pgfplots to plot a graph but I run into the following error:

! Undefined control sequence.
\pgfplots@width ->0.95\textwidth -\heightof
{ylabel}-\widthof {ymax}

Here is my document:

\documentclass[12pt]{article}

\usepackage{pgfplots}
\usepackage{pgf}            
\usepackage{tikz}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{external} 
\tikzexternalize

\begin{document}
Hello world!
\begin{figure}[htbp]
    \centering
    \begin{tikzpicture}
        \begin{axis}[%
        scale only axis,
        separate axis lines,
        ytick={-20,0,20,40,60,80,100,120,140},
        xmin=1,
        xmax=1.8,
        xlabel={$\lambda (\epsilon + 1)$ },
        ymin=-20,
        ymax=140,
        ylabel={$\sigma_{11} (kPa)$},
        legend style={legend pos=north west, legend cell align=left,align=left,draw=none},
        yticklabel style={align=right,inner sep=0pt,xshift=-0.1cm}, 
        grid=none,
        max space between ticks=40,
        major tick length=0.15cm,
        minor tick length=0.075cm,
        tick style={semithick,color=black}, 
        width=0.95\textwidth-\heightof{ylabel}-\widthof{ymax},
        height=0.5\textwidth ]
\addplot [color=black,mark size=2.5pt,only marks,mark=*,mark options={solid,fill=white!75!blue}]
  table[row sep=crcr]{%
1.00781861  0.0102718\\
1.0193275   -0.00690492\\
1.0289739   0.0408018\\
1.040467    0.0701334\\
1.05104 0.0993509\\
};
\addlegendentry{Experimental data};

\addplot [color=blue,solid,line width=1.0pt]
  table[row sep=crcr]{%
1.00781861  0.190117075896132\\
1.0193275   0.474231238225642\\
1.0289739   0.717201161857507\\
1.040467    1.01366753959628\\
1.05104 1.29424479212858\\
};
\addlegendentry{Ogden model};

\addplot [color=red,solid,line width=1.0pt]
  table[row sep=crcr]{%
1.00781861  0.777179697089887\\
1.0193275   1.92137205791344\\
1.0289739   2.88076259714836\\
1.040467    4.02448983176329\\
1.05104 5.07751266247692\\
};
\addlegendentry{Neo-Hookean model};

\addplot [color=green,solid,line width=1.0pt]
  table[row sep=crcr]{%
1.00781861  -3.7155599786856\\
1.0193275   -7.79892723072965\\
1.0289739   -10.2011747706551\\
1.040467    -12.1140706845337\\
1.05104 -13.154421182274\\
};
\addlegendentry{Mooney-Rivlin model};

        \end{axis} 
    \end{tikzpicture}
    \caption[]{Experimental data fitted to the hyperelastic models models}
    \label{figure:curve_fitting_from_data}
\end{figure}
\end{document}
Stefan Pinnow
  • 29,535
  • 4
    TikZ v2.x defined the macros \widthof, \heightof and \depthof, but these were removed in v3. Instead there are corresponding functions in the math library, so you can use width("text") and height("text") instead. Or possibly add \usepackage{calc}, as the calc package does define \widthof etc. (if I remember correctly). – Torbjørn T. Apr 11 '17 at 12:59
  • I added \usepackage{calc} now I get the following error:! Undefined control sequence. \pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@ –  Apr 11 '17 at 13:04
  • 2
    Right, so use width("text") instead of \widthof{text}. – Torbjørn T. Apr 11 '17 at 13:05

0 Answers0