1

I've been trying to produce a plot which has a contour of the magnitude of a vector field and the same vector field plotted on top.

There seems to be no problem with generating the contour, but I cannot seem to find a way to plot the vector field (with gnuplot). The closest I got with the code below

\begin{filecontents}{test.dat}
      0.25000000   0.00000000   0.01244442  -0.00102820
      0.24745536   0.03557871   0.01458852  -0.00682528
      0.23987324   0.07043314   0.01684754  -0.01216321
      0.22740800   0.10385375   0.01868942  -0.01674498
      0.21031338   0.13516020   0.02011573  -0.01983434
      0.18893739   0.16371518   0.02097252  -0.02141963
      0.16371518   0.18893739   0.02121539  -0.02188232
      0.13516020   0.21031338   0.02072794  -0.02109773
      0.10385375   0.22740800   0.01838178  -0.01992040
      0.07043314   0.23987324   0.01458487  -0.01831782
      0.03557871   0.24745536   0.00936304  -0.01729592
      0.00000000   0.25000000   0.00320612  -0.01703388
     -0.03557871   0.24745536  -0.00308422  -0.01699850
     -0.07043314   0.23987324  -0.00840902  -0.01795878
     -0.10385375   0.22740800  -0.01241573  -0.01954049
     -0.13516020   0.21031338  -0.01463361  -0.02041608
     -0.16371518   0.18893739  -0.01553877  -0.02065888
     -0.18893739   0.16371518  -0.01528775  -0.02006555
     -0.21031338   0.13516020  -0.01439546  -0.01828976
     -0.22740800   0.10385375  -0.01306564  -0.01499391
     -0.23987324   0.07043314  -0.01197325  -0.01054383
     -0.24745536   0.03557871  -0.01158730  -0.00510307
     -0.25000000   0.00000000  -0.01244442   0.00102820
     -0.24745536  -0.03557871  -0.01458851   0.00682528
     -0.23987324  -0.07043314  -0.01684754   0.01216320
     -0.22740800  -0.10385375  -0.01868942   0.01674497
     -0.21031338  -0.13516020  -0.02011572   0.01983433
     -0.18893739  -0.16371518  -0.02097252   0.02141962
     -0.16371518  -0.18893739  -0.02121538   0.02188231
     -0.13516020  -0.21031338  -0.02072793   0.02109773
     -0.10385375  -0.22740800  -0.01838178   0.01992039
     -0.07043314  -0.23987324  -0.01458487   0.01831781
     -0.03557871  -0.24745536  -0.00936304   0.01729591
     -0.00000000  -0.25000000  -0.00320612   0.01703387
      0.03557871  -0.24745536   0.00308422   0.01699850
      0.07043314  -0.23987324   0.00840901   0.01795877
      0.10385375  -0.22740800   0.01241572   0.01954048
      0.13516020  -0.21031338   0.01463361   0.02041607
      0.16371518  -0.18893739   0.01553876   0.02065887
      0.18893739  -0.16371518   0.01528774   0.02006554
      0.21031338  -0.13516020   0.01439545   0.01828975
      0.22740800  -0.10385375   0.01306563   0.01499391
      0.23987324  -0.07043314   0.01197325   0.01054382
      0.24745536  -0.03557871   0.01158730   0.00510307
      0.25000000  -0.00000000   0.01244442  -0.00102820

      0.50000000   0.00000000   0.03487771  -0.00012289
      0.49491072   0.07115742   0.03855601  -0.02675519
      0.47974649   0.14086628   0.04611102  -0.05034315
      0.45481600   0.20770751   0.05567821  -0.06884314
      0.42062677   0.27032041   0.06496719  -0.07975622
      0.37787479   0.32743037   0.07033963  -0.08097639
      0.32743037   0.37787479   0.07422312  -0.07974617
      0.27032041   0.42062677   0.07327565  -0.07441409
      0.20770751   0.45481600   0.06294688  -0.06647461
      0.14086628   0.47974649   0.04578087  -0.05999006
      0.07115742   0.49491072   0.02326903  -0.05602799
      0.00000000   0.50000000   0.00126173  -0.05616847
     -0.07115742   0.49491072  -0.02097079  -0.05805461
     -0.14086628   0.47974649  -0.04200299  -0.06172077
     -0.20770751   0.45481600  -0.05699274  -0.06761936
     -0.27032041   0.42062677  -0.06397533  -0.07512127
     -0.32743037   0.37787479  -0.06457599  -0.08089965
     -0.37787479   0.32743037  -0.05840981  -0.08059812
     -0.42062677   0.27032041  -0.05149746  -0.07728243
     -0.45481600   0.20770751  -0.04454231  -0.06431185
     -0.47974649   0.14086628  -0.03991223  -0.04605772
     -0.49491072   0.07115742  -0.03615646  -0.02433877
     -0.50000000   0.00000000  -0.03487771   0.00012290
     -0.49491072  -0.07115742  -0.03855601   0.02675517
     -0.47974649  -0.14086628  -0.04611101   0.05034313
     -0.45481600  -0.20770751  -0.05567821   0.06884312
     -0.42062677  -0.27032041  -0.06496718   0.07975621
     -0.37787479  -0.32743037  -0.07033962   0.08097639
     -0.32743037  -0.37787479  -0.07422311   0.07974617
     -0.27032041  -0.42062677  -0.07327564   0.07441408
     -0.20770751  -0.45481600  -0.06294687   0.06647460
     -0.14086628  -0.47974649  -0.04578086   0.05999005
     -0.07115742  -0.49491072  -0.02326903   0.05602798
     -0.00000000  -0.50000000  -0.00126173   0.05616846
      0.07115742  -0.49491072   0.02097079   0.05805460
      0.14086628  -0.47974649   0.04200298   0.06172077
      0.20770751  -0.45481600   0.05699273   0.06761935
      0.27032041  -0.42062677   0.06397532   0.07512126
      0.32743037  -0.37787479   0.06457598   0.08089964
      0.37787479  -0.32743037   0.05840980   0.08059811
      0.42062677  -0.27032041   0.05149746   0.07728242
      0.45481600  -0.20770751   0.04454230   0.06431184
      0.47974649  -0.14086628   0.03991223   0.04605770
      0.49491072  -0.07115742   0.03615646   0.02433875
      0.50000000  -0.00000000   0.03487771  -0.00012289

      0.75000000   0.00000000   0.04524078  -0.00095396
      0.74236608   0.10673613   0.05306879  -0.04574295
      0.71961973   0.21129942   0.06502646  -0.08325645
      0.68222400   0.31156126   0.07715058  -0.11208698
      0.63094015   0.40548061   0.09414626  -0.12967701
      0.56681218   0.49114555   0.11160899  -0.13672866
      0.49114555   0.56681218   0.12246886  -0.13413226
      0.40548061   0.63094015   0.12677188  -0.12876916
      0.31156126   0.68222400   0.11433009  -0.11917672
      0.21129942   0.71961973   0.08403693  -0.10706906
      0.10673613   0.74236608   0.04901281  -0.10124578
      0.00000000   0.75000000   0.00656410  -0.10326009
     -0.10673613   0.74236608  -0.04057348  -0.10483901
     -0.21129942   0.71961973  -0.07758878  -0.11251418
     -0.31156126   0.68222400  -0.10366723  -0.12354200
     -0.40548061   0.63094015  -0.11189908  -0.13212260
     -0.49114555   0.56681218  -0.10742430  -0.13646548
     -0.56681218   0.49114555  -0.09482291  -0.13823196
     -0.63094015   0.40548061  -0.07621721  -0.12980712
     -0.68222400   0.31156126  -0.05915587  -0.10778776
     -0.71961973   0.21129942  -0.04817206  -0.07545381
     -0.74236608   0.10673613  -0.04500190  -0.03925315
     -0.75000000   0.00000000  -0.04524078   0.00095397
     -0.74236608  -0.10673613  -0.05306879   0.04574293
     -0.71961973  -0.21129942  -0.06502645   0.08325644
     -0.68222400  -0.31156126  -0.07715057   0.11208696
     -0.63094015  -0.40548061  -0.09414625   0.12967700
     -0.56681218  -0.49114555  -0.11160898   0.13672866
     -0.49114555  -0.56681218  -0.12246886   0.13413226
     -0.40548061  -0.63094015  -0.12677188   0.12876915
     -0.31156126  -0.68222400  -0.11433009   0.11917672
     -0.21129942  -0.71961973  -0.08403693   0.10706906
     -0.10673613  -0.74236608  -0.04901281   0.10124577
     -0.00000000  -0.75000000  -0.00656410   0.10326008
      0.10673613  -0.74236608   0.04057348   0.10483901
      0.21129942  -0.71961973   0.07758878   0.11251418
      0.31156126  -0.68222400   0.10366722   0.12354200
      0.40548061  -0.63094015   0.11189908   0.13212260
      0.49114555  -0.56681218   0.10742429   0.13646548
      0.56681218  -0.49114555   0.09482290   0.13823196
      0.63094015  -0.40548061   0.07621721   0.12980711
      0.68222400  -0.31156126   0.05915587   0.10778775
      0.71961973  -0.21129942   0.04817206   0.07545380
      0.74236608  -0.10673613   0.04500190   0.03925313
      0.75000000  -0.00000000   0.04524078  -0.00095396

      1.00000000   0.00000000   0.03113259  -0.00274303
      0.98982144   0.14231484   0.04344356  -0.03983086
      0.95949297   0.28173256   0.05721310  -0.07792868
      0.90963200   0.41541501   0.07255247  -0.10553155
      0.84125353   0.54064082   0.09357257  -0.12897419
      0.75574957   0.65486073   0.11220525  -0.13997753
      0.65486073   0.75574957   0.12412760  -0.13308707
      0.54064082   0.84125353   0.12962609  -0.12306648
      0.41541501   0.90963200   0.11947635  -0.11856376
      0.28173256   0.95949297   0.09467411  -0.12315820
      0.14231484   0.98982144   0.05571594  -0.13168950
      0.00000000   1.00000000   0.01109093  -0.13925843
     -0.14231484   0.98982144  -0.03255831  -0.13580838
     -0.28173256   0.95949297  -0.07250166  -0.12487736
     -0.41541501   0.90963200  -0.09813630  -0.11775850
     -0.54064082   0.84125353  -0.10600721  -0.12160042
     -0.65486073   0.75574957  -0.10231271  -0.12708971
     -0.75574957   0.65486073  -0.08904257  -0.12966839
     -0.84125353   0.54064082  -0.07111012  -0.11957096
     -0.90963200   0.41541501  -0.05093528  -0.09456304
     -0.95949297   0.28173256  -0.03515922  -0.06341403
     -0.98982144   0.14231484  -0.03025696  -0.03027786
     -1.00000000   0.00000000  -0.03113259   0.00274304
     -0.98982144  -0.14231484  -0.04344356   0.03983085
     -0.95949297  -0.28173256  -0.05721310   0.07792867
     -0.90963200  -0.41541501  -0.07255247   0.10553155
     -0.84125353  -0.54064082  -0.09357256   0.12897419
     -0.75574957  -0.65486073  -0.11220525   0.13997754
     -0.65486073  -0.75574957  -0.12412760   0.13308708
     -0.54064082  -0.84125353  -0.12962609   0.12306649
     -0.41541501  -0.90963200  -0.11947636   0.11856377
     -0.28173256  -0.95949297  -0.09467412   0.12315820
     -0.14231484  -0.98982144  -0.05571594   0.13168950
     -0.00000000  -1.00000000  -0.01109093   0.13925843
      0.14231484  -0.98982144   0.03255832   0.13580837
      0.28173256  -0.95949297   0.07250167   0.12487736
      0.41541501  -0.90963200   0.09813630   0.11775851
      0.54064082  -0.84125353   0.10600721   0.12160043
      0.65486073  -0.75574957   0.10231271   0.12708972
      0.75574957  -0.65486073   0.08904257   0.12966840
      0.84125353  -0.54064082   0.07111012   0.11957096
      0.90963200  -0.41541501   0.05093528   0.09456304
      0.95949297  -0.28173256   0.03515922   0.06341402
      0.98982144  -0.14231484   0.03025696   0.03027785
      1.00000000  -0.00000000   0.03113259  -0.00274303
\end{filecontents}
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.13}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            width=0.9\textwidth,
            height=0.9\textwidth,
            scale only axis,
            ymin=0, ymax=1,
            xmin=0, xmax=1,
            xlabel={$r_1/d$},
            ylabel={$r_2/d$},
            view={0}{90},
            colormap/hot2,
        ]
            \addplot3 [raw gnuplot,surf,shader=interp]
                gnuplot [id={surf}] {
                    set parametric;
                    set pm3d map interpolate 1,1;
                    plot 'test.dat' u 1:2:(sqrt(($3)^2+($4)^2));
            };

            \addplot [raw gnuplot] gnuplot {
                plot 'test.dat' u 1:2:(($3)/(sqrt(($3)^2+($4)^2))):(($4)/(sqrt(($3)^2+($4)^2))) with vectors;
            };
        \end{axis}
    \end{tikzpicture}
 \end{document}

was to generate the desired contour but the vector field does not show, I get iso-radial lines instead as in the image below

  • 2
    Could you include the data file (or at least a sample of it) and complete the code snippet to make it a compilable minimal document? That'll make it easier for others to work on a solution. – Jake Mar 9 '16 at 21:11
  • Hi @Jake , I have edited the example such that it compiles with pdflatex. I have created a smaller example file but have no idea how to attached it here, you can get it from the dropbox link: dropbox.com/s/2id3jqsq9m32y36/test.dat?dl=0 – Felipe Mar 9 '16 at 21:36
0

I have given up on trying to use gnuplot for the quivers... I managed the following workaround:

\addplot [black,quiver={u={\thisrowno{2}/(sqrt((\thisrowno{2})^2+(\thisrowno{3})^2))},v={\thisrowno{3}/(sqrt((\thisrowno{2})^2+(\thisrowno{3})^2))}},-stealth] table {test.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.