2

I have a Matlab plot shown below which I want to replicate in Latex. The data for Matlab is:

i_whole=[
     0         0         0         0         0
3.7000    3.8000    3.8000    4.2000    3.7000
7.7000    7.9000    7.8000    7.8000    7.8000
11.7000   11.8000   12.1000   11.8000   11.5000
15.7000   15.8000   15.6000   16.2000   16.1000
20.4000   19.8000   19.8000   19.4000   19.7000
23.7000   23.7000   23.7000   23.7000   23.9000
27.7000   27.7000   28.0000   28.2000   27.6000
31.7000   32.2000   31.8000   32.0000   32.2000
35.7000   36.1000   36.2000   35.7000   35.9000
39.7000   39.6000   39.6000   40.4000   39.9000
43.7000   43.9000   43.8000   44.2000   44.2000
47.7000   47.9000   47.6000   47.6000   47.8000
52.0000   52.2000   51.5000   52.0000   52.2000
56.4000   55.8000   56.0000   56.1000   55.9000
60.0000   59.9000   60.1000   59.5000   59.7000]';

p_whole=[
4.8E-10 1.98E-09    2.4E-09 2.66E-09    2.9E-09
0.000000717 5.501E-07   4.811E-07   4.829E-07   0.000000322
0.000004215 0.000003035 0.000002194 0.000001707 0.00000134
0.0001026   0.0000655   0.00003436  0.000004427 0.00000311
0.0002143   0.0001659   0.00011038  0.0000754   0.0000319
0.00035 0.0002725   0.0002108   0.0001409   0.00008932
0.0004489   0.000379    0.000308    0.0002356   0.0001693
0.0005689   0.000492    0.000419    0.00034 0.000243
0.0006918   0.0006185   0.0005163   0.000439    0.000333
0.00081 0.000721    0.0006322   0.0005193   0.000418
0.000927    0.000826    0.00072 0.00063 0.000504
0.001045    0.000948    0.0008313   0.00072 0.000596
0.0011625   0.0010538   0.000925    0.0007999   0.000671
0.0012887   0.001168    0.001022    0.000901    0.0007575
0.001419    0.001263    0.0011366   0.00098 0.0008383
0.0015187   0.001373    0.001232    0.001066    0.000912
]';

t_whole=[
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40
20    25    30    35    40]';

The surf plot in Matlab is like this:

surf(i_whole,t_whole,p_whole)

I get this plot:

3d plot in Matlab

I am trying to plot this in Latex using pgf plots, I use the following code:

\begin{figure}[h]
\begin{tikzpicture}
    \begin{axis}[
        xlabel={Temperature [$^{\circ}C$]},
        ylabel={Current [mA]},
        zlabel={Power [W]},
        grid=both]  
    \addplot3[surf,shader=interp,samples=100] table [x=t,y=i,z=p] {ipt3d.dat};
    \end{axis}
\end{tikzpicture}
\end{figure}

Where the file iptd3.dat is like this, which is just combining the matrix i_whole etc. into 3d coordinates:

i       p       t
0.00000000000   0.00000000048   20.00000000000
3.70000000000   0.00000071700   20.00000000000
7.70000000000   0.00000421500   20.00000000000
11.70000000000  0.00010260000   20.00000000000
15.70000000000  0.00021430000   20.00000000000
20.40000000000  0.00035000000   20.00000000000
23.70000000000  0.00044890000   20.00000000000
27.70000000000  0.00056890000   20.00000000000
31.70000000000  0.00069180000   20.00000000000
35.70000000000  0.00081000000   20.00000000000
39.70000000000  0.00092700000   20.00000000000
43.70000000000  0.00104500000   20.00000000000
47.70000000000  0.00116250000   20.00000000000
52.00000000000  0.00128870000   20.00000000000
56.40000000000  0.00141900000   20.00000000000
60.00000000000  0.00151870000   20.00000000000
0.00000000000   0.00000000198   25.00000000000
3.80000000000   0.00000055010   25.00000000000
7.90000000000   0.00000303500   25.00000000000
11.80000000000  0.00006550000   25.00000000000
15.80000000000  0.00016590000   25.00000000000
19.80000000000  0.00027250000   25.00000000000
23.70000000000  0.00037900000   25.00000000000
27.70000000000  0.00049200000   25.00000000000
32.20000000000  0.00061850000   25.00000000000
36.10000000000  0.00072100000   25.00000000000
39.60000000000  0.00082600000   25.00000000000
43.90000000000  0.00094800000   25.00000000000
47.90000000000  0.00105380000   25.00000000000
52.20000000000  0.00116800000   25.00000000000
55.80000000000  0.00126300000   25.00000000000
59.90000000000  0.00137300000   25.00000000000
0.00000000000   0.00000000240   30.00000000000
3.80000000000   0.00000048110   30.00000000000
7.80000000000   0.00000219400   30.00000000000
12.10000000000  0.00003436000   30.00000000000
15.60000000000  0.00011038000   30.00000000000
19.80000000000  0.00021080000   30.00000000000
23.70000000000  0.00030800000   30.00000000000
28.00000000000  0.00041900000   30.00000000000
31.80000000000  0.00051630000   30.00000000000
36.20000000000  0.00063220000   30.00000000000
39.60000000000  0.00072000000   30.00000000000
43.80000000000  0.00083130000   30.00000000000
47.60000000000  0.00092500000   30.00000000000
51.50000000000  0.00102200000   30.00000000000
56.00000000000  0.00113660000   30.00000000000
60.10000000000  0.00123200000   30.00000000000
0.00000000000   0.00000000266   35.00000000000
4.20000000000   0.00000048290   35.00000000000
7.80000000000   0.00000170700   35.00000000000
11.80000000000  0.00000442700   35.00000000000
16.20000000000  0.00007540000   35.00000000000
19.40000000000  0.00014090000   35.00000000000
23.70000000000  0.00023560000   35.00000000000
28.20000000000  0.00034000000   35.00000000000
32.00000000000  0.00043900000   35.00000000000
35.70000000000  0.00051930000   35.00000000000
40.40000000000  0.00063000000   35.00000000000
44.20000000000  0.00072000000   35.00000000000
47.60000000000  0.00079990000   35.00000000000
52.00000000000  0.00090100000   35.00000000000
56.10000000000  0.00098000000   35.00000000000
59.50000000000  0.00106600000   35.00000000000
0.00000000000   0.00000000290   40.00000000000
3.70000000000   0.00000032200   40.00000000000
7.80000000000   0.00000134000   40.00000000000
11.50000000000  0.00000311000   40.00000000000
16.10000000000  0.00003190000   40.00000000000
19.70000000000  0.00008932000   40.00000000000
23.90000000000  0.00016930000   40.00000000000
27.60000000000  0.00024300000   40.00000000000
32.20000000000  0.00033300000   40.00000000000
35.90000000000  0.00041800000   40.00000000000
39.90000000000  0.00050400000   40.00000000000
44.20000000000  0.00059600000   40.00000000000
47.80000000000  0.00067100000   40.00000000000
52.20000000000  0.00075750000   40.00000000000
55.90000000000  0.00083830000   40.00000000000
59.70000000000  0.00091200000   40.00000000000

But the plot that I get in Latex is nowhere close to that one as Matlab:

3d Plot in Latex

How to make it resemble like that one in Matlab. Would be grateful if someone helps!

  • For problem solvers: 1. name the ipt3d.dat, not iptd3.dat. 2. This is related to the mesh/cols and mesh/rows settings, but the output data file seems weird. See also: tex.stackexchange.com/questions/187091/… Also, there are 80 rows and 3 columns. Possibly you have to adjust the way pgfplots reads things. – 1010011010 Nov 9 '14 at 10:08
2

How did you generate the 3x80 table? I have used

T = [ i_whole(:) t_whole(:) p_whole(:) ]
save -ascii T.dat T

Afterwards, I configured mesh/ordering=y varies,mesh/cols=16 and got the expected result (I also added view=-30 to see a similar part of the image):

enter image description here

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.9}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xlabel={Temperature [$^{\circ}C$]},
        ylabel={Current [mA]},
        zlabel={Power [W]},
        view/h=-30,
        grid=both]  
    \addplot3[surf,
        shader=interp,
        mesh/ordering=y varies,mesh/cols=16] table {T.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

Further references to this approach can be found in the pgfplots manual, in my release it is "7.2.1 Importing Mesh Data From Matlab To PGFPlots".

With my matrix concatenation commands, the data file T.dat is

 0.00000000e+00 2.00000000e+01 4.80000000e-10
 0.00000000e+00 2.50000000e+01 1.98000000e-09
 0.00000000e+00 3.00000000e+01 2.40000000e-09
 0.00000000e+00 3.50000000e+01 2.66000000e-09
 0.00000000e+00 4.00000000e+01 2.90000000e-09
 3.70000000e+00 2.00000000e+01 7.17000000e-07
 3.80000000e+00 2.50000000e+01 5.50100000e-07
 3.80000000e+00 3.00000000e+01 4.81100000e-07
 4.20000000e+00 3.50000000e+01 4.82900000e-07
 3.70000000e+00 4.00000000e+01 3.22000000e-07
 7.70000000e+00 2.00000000e+01 4.21500000e-06
 7.90000000e+00 2.50000000e+01 3.03500000e-06
 7.80000000e+00 3.00000000e+01 2.19400000e-06
 7.80000000e+00 3.50000000e+01 1.70700000e-06
 7.80000000e+00 4.00000000e+01 1.34000000e-06
 1.17000000e+01 2.00000000e+01 1.02600000e-04
 1.18000000e+01 2.50000000e+01 6.55000000e-05
 1.21000000e+01 3.00000000e+01 3.43600000e-05
 1.18000000e+01 3.50000000e+01 4.42700000e-06
 1.15000000e+01 4.00000000e+01 3.11000000e-06
 1.57000000e+01 2.00000000e+01 2.14300000e-04
 1.58000000e+01 2.50000000e+01 1.65900000e-04
 1.56000000e+01 3.00000000e+01 1.10380000e-04
 1.62000000e+01 3.50000000e+01 7.54000000e-05
 1.61000000e+01 4.00000000e+01 3.19000000e-05
 2.04000000e+01 2.00000000e+01 3.50000000e-04
 1.98000000e+01 2.50000000e+01 2.72500000e-04
 1.98000000e+01 3.00000000e+01 2.10800000e-04
 1.94000000e+01 3.50000000e+01 1.40900000e-04
 1.97000000e+01 4.00000000e+01 8.93200000e-05
 2.37000000e+01 2.00000000e+01 4.48900000e-04
 2.37000000e+01 2.50000000e+01 3.79000000e-04
 2.37000000e+01 3.00000000e+01 3.08000000e-04
 2.37000000e+01 3.50000000e+01 2.35600000e-04
 2.39000000e+01 4.00000000e+01 1.69300000e-04
 2.77000000e+01 2.00000000e+01 5.68900000e-04
 2.77000000e+01 2.50000000e+01 4.92000000e-04
 2.80000000e+01 3.00000000e+01 4.19000000e-04
 2.82000000e+01 3.50000000e+01 3.40000000e-04
 2.76000000e+01 4.00000000e+01 2.43000000e-04
 3.17000000e+01 2.00000000e+01 6.91800000e-04
 3.22000000e+01 2.50000000e+01 6.18500000e-04
 3.18000000e+01 3.00000000e+01 5.16300000e-04
 3.20000000e+01 3.50000000e+01 4.39000000e-04
 3.22000000e+01 4.00000000e+01 3.33000000e-04
 3.57000000e+01 2.00000000e+01 8.10000000e-04
 3.61000000e+01 2.50000000e+01 7.21000000e-04
 3.62000000e+01 3.00000000e+01 6.32200000e-04
 3.57000000e+01 3.50000000e+01 5.19300000e-04
 3.59000000e+01 4.00000000e+01 4.18000000e-04
 3.97000000e+01 2.00000000e+01 9.27000000e-04
 3.96000000e+01 2.50000000e+01 8.26000000e-04
 3.96000000e+01 3.00000000e+01 7.20000000e-04
 4.04000000e+01 3.50000000e+01 6.30000000e-04
 3.99000000e+01 4.00000000e+01 5.04000000e-04
 4.37000000e+01 2.00000000e+01 1.04500000e-03
 4.39000000e+01 2.50000000e+01 9.48000000e-04
 4.38000000e+01 3.00000000e+01 8.31300000e-04
 4.42000000e+01 3.50000000e+01 7.20000000e-04
 4.42000000e+01 4.00000000e+01 5.96000000e-04
 4.77000000e+01 2.00000000e+01 1.16250000e-03
 4.79000000e+01 2.50000000e+01 1.05380000e-03
 4.76000000e+01 3.00000000e+01 9.25000000e-04
 4.76000000e+01 3.50000000e+01 7.99900000e-04
 4.78000000e+01 4.00000000e+01 6.71000000e-04
 5.20000000e+01 2.00000000e+01 1.28870000e-03
 5.22000000e+01 2.50000000e+01 1.16800000e-03
 5.15000000e+01 3.00000000e+01 1.02200000e-03
 5.20000000e+01 3.50000000e+01 9.01000000e-04
 5.22000000e+01 4.00000000e+01 7.57500000e-04
 5.64000000e+01 2.00000000e+01 1.41900000e-03
 5.58000000e+01 2.50000000e+01 1.26300000e-03
 5.60000000e+01 3.00000000e+01 1.13660000e-03
 5.61000000e+01 3.50000000e+01 9.80000000e-04
 5.59000000e+01 4.00000000e+01 8.38300000e-04
 6.00000000e+01 2.00000000e+01 1.51870000e-03
 5.99000000e+01 2.50000000e+01 1.37300000e-03
 6.01000000e+01 3.00000000e+01 1.23200000e-03
 5.95000000e+01 3.50000000e+01 1.06600000e-03
 5.97000000e+01 4.00000000e+01 9.12000000e-04

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.