![在 Latex 中绘制 3d 图时出现问题,我有一个 Matlab 示例图](https://linux22.com/image/301263/%E5%9C%A8%20Latex%20%E4%B8%AD%E7%BB%98%E5%88%B6%203d%20%E5%9B%BE%E6%97%B6%E5%87%BA%E7%8E%B0%E9%97%AE%E9%A2%98%EF%BC%8C%E6%88%91%E6%9C%89%E4%B8%80%E4%B8%AA%20Matlab%20%E7%A4%BA%E4%BE%8B%E5%9B%BE.png)
我有一个如下所示的 Matlab 图,我想在 Latex 中复制它。Matlab 的数据是:
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]';
Matlab 中的冲浪图如下:
surf(i_whole,t_whole,p_whole)
我得到了这个情节:
我正在尝试使用 pgf 图在 Latex 中绘制这个图表,我使用以下代码:
\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}
文件 iptd3.dat 是这样的,它只是将矩阵 i_whole 等组合成 3d 坐标:
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
但是我在 Latex 中得到的图与 Matlab 中的图完全不同:
如何使其类似于 Matlab 中的那个。如果有人能帮助我将不胜感激!
答案1
你是如何生成 3x80 表的?我使用过
T = [ i_whole(:) t_whole(:) p_whole(:) ]
save -ascii T.dat T
随后,我进行了配置mesh/ordering=y varies,mesh/cols=16
并得到了预期的结果(我还添加了view=-30
以查看图像的类似部分):
\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}
可以在手册中找到对此方法的进一步参考pgfplots
,在我的版本中它是“7.2.1 将网格数据从 Matlab 导入 PGFPlots”。
使用我的矩阵连接命令,数据文件T.dat
是
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