12

I would like to draw a vector field from a data file. I tried to adapt code from Manual for Package pgfplots but this doesn't work

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotstableread{vector_field.dat}{\loadedtable}

\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Quiver and plot table]
\addplot[blue,quiver={u=\thisrow{u},v=\thisrow{v}},-stealth] table from  \loadedtable;
\end{axis}
\end{tikzpicture}
\end{document}

where data file vector_field.dat is :

x y u v
0 0 1 0
1 1 1 1
2 4 1 4
3 9 1 6
4 16 1 8

During compilation I get for example this error:

! Undefined control sequence.
\pgfk@/data point/quiver/u ->\thisrow
{u}
l.8 ...row{v}},-stealth] table from \loadedtable;
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Package PGF Math Error: Unknown function `u' (in '{u}').

Does anyone now how to solve it? I would be grateful for any help.

8

I get the error message ! Package PGF Math Error: Unknown function `thisrow_unavailable_load_table_directly'. If I do that, that is, if I use \addplot ... table {vector_field.csv};, the document compiles:

\documentclass{article}
\usepackage{pgfplots}

\begin{filecontents}{vector_field.dat}
x y u v
0 0 1 0
1 1 1 1
2 4 1 4
3 9 1 6
4 16 1 8
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Quiver and plot table]
\addplot[blue,quiver={u=\thisrow{u},v=\thisrow{v}},-stealth] table {vector_field.dat};
\end{axis}
\end{tikzpicture}
\end{document}
  • I'm not sure if I read this answer correctly, but I paste the MWE as is, (pgfplots 1.5.1), and I still get "! Package PGF Math Error: Unknown function 'thisrow_unavailable_load_table_directly'". – sdaau Jul 6 '14 at 6:13
  • I think what he meant is that you should provide the filename instead of using pgfplotstableread to avoid this error. At least, that is how it worked for me. – Alfred M. Sep 18 '14 at 7:45
1

I'm adding a new answer because the MWE given by Jake is not working for me.

\documentclass{article}
\usepackage{pgfplots}

%To create a .dat file (not required if you already have the file in the same folder)
\begin{filecontents}{vector_field.dat}
    x y u v
    0 0 1 0
    1 1 1 1
    2 4 1 4
    3 9 1 6
    4 16 1 8
\end{filecontents}


\begin{document}
    \begin{tikzpicture}
        \begin{axis}
        % Loading directly the table, as suggested by Jake and Alfred M.
        \addplot[blue,quiver={u=\thisrow{u},v=\thisrow{v}},-stealth] table {vector_field.dat};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

  • 1
    Thanks for the heads up, I now corrected the MWE in my answer. – Jake Jul 26 '16 at 17:44
0

It seems to be a little old question and that you have already figured it out. Anyway, I was dealing with the same problem and could solve it just indicating x and y columns.

Then, when you read it from a file, you have to tell where x and y are. In my case, this piece of code worked perfectly:

\addplot [color=black, mark=none, quiver={u=\thisrow{u},v=\thisrow{v}}, -stealth]
  table [x={x}, y={y}]
  {Data/VectorGraph2D_Pos_Vel_YZ.dat};

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.