使用 Matlab 数据将 3D 绘制为 2D 图

使用 Matlab 数据将 3D 绘制为 2D 图

我正在尝试将 3d 数据绘制为 2d(请参阅附图在此处输入图片描述)。

在 Tex(或 Matlab)中,这可能吗?(通常,这是以图例的形式完成的,但是,当不允许使用颜色时,我必须像附图中那样绘制它)。如果可以,请提供任何提示。提前谢谢

这也是数据的一个示例:

X=[0 0 0 0 0
0.00499487214258387 0.0100271322719341  0.0151355841667174  0.0203619904285679  0.0257528910437245
0.00703013931750997 0.0141123715001326  0.0213007419561194  0.0286533748405864  0.0362349750090093
0.00856912164753604 0.0172011015018718  0.0259611298569260  0.0349192664533911  0.0441534216317338
0.00984769541100846 0.0197669024060679  0.0298317587516411  0.0401218833508729  0.0507257254049430
0.0109577332470996  0.0219942405774403  0.0331911596116199  0.0446361019206510  0.0564262963381876
0.0119466084732432  0.0239782392419037  0.0361829739474490  0.0486552739640120  0.0614998638245181
0.0128426154484001  0.0257757149277838  0.0388930053871466  0.0522949117805015  0.0660926587477192
0.0136642899493110  0.0274238903416811  0.0413774721254582  0.0556307081325855  0.0703005193527485
0.0144245776620953  0.0289487637697525  0.0436756433487295  0.0587155421791397  0.0741904098771546
0.0151329564382696  0.0303693701768318  0.0458162730087464  0.0615881383770832  0.0778113778863288
0.0157966212085941  0.0317001603416950  0.0478211921655991  0.0642779014739504  0.0812006730740997
0.0164211931300526  0.0329524247496926  0.0497074590478197  0.0668078104510510  0.0843874098612964
0.0170111676966756  0.0341351933703888  0.0514887177522871  0.0691962474012896  0.0873948821954542
0.0175702105696051  0.0352558296774944  0.0531760952694321  0.0714582050315404  0.0902420919849960
0.0181013600452389  0.0363204372087640  0.0547788154484420  0.0736061131758165  0.0929447953582426
0.0186071698801841  0.0373341463673818  0.0563046321253931  0.0756504218986758  0.0955162408504069
0.0190898126701751  0.0383013220178056  0.0577601426467341  0.0776000236025984  0.0979677038151599
0.0195511563564558  0.0392257171221451  0.0591510199088859  0.0794625654482437  0.100308881996065
0.0199928219502558  0.0401105886622858  0.0604821874442227  0.0812446851052654  0.102548194045946];

Y=[1 1 1 1 1
1.00100502512563 1.00100502512563 1.00100502512563 1.00100502512563 1.00100502512563
1.00201005025126 1.00201005025126 1.00201005025126 1.00201005025126 1.00201005025126
1.00301507537688 1.00301507537688 1.00301507537688 1.00301507537688 1.00301507537688
1.00402010050251 1.00402010050251 1.00402010050251 1.00402010050251 1.00402010050251
1.00502512562814 1.00502512562814 1.00502512562814 1.00502512562814 1.00502512562814
1.00603015075377 1.00603015075377 1.00603015075377 1.00603015075377 1.00603015075377
1.00703517587940 1.00703517587940 1.00703517587940 1.00703517587940 1.00703517587940
1.00804020100503 1.00804020100503 1.00804020100503 1.00804020100503 1.00804020100503
1.00904522613065 1.00904522613065 1.00904522613065 1.00904522613065 1.00904522613065
1.01005025125628 1.01005025125628 1.01005025125628 1.01005025125628 1.01005025125628
1.01105527638191 1.01105527638191 1.01105527638191 1.01105527638191 1.01105527638191
1.01206030150754 1.01206030150754 1.01206030150754 1.01206030150754 1.01206030150754
1.01306532663317 1.01306532663317 1.01306532663317 1.01306532663317 1.01306532663317
1.01407035175879 1.01407035175879 1.01407035175879 1.01407035175879 1.01407035175879
1.01507537688442 1.01507537688442 1.01507537688442 1.01507537688442 1.01507537688442
1.01608040201005 1.01608040201005 1.01608040201005 1.01608040201005 1.01608040201005
1.01708542713568 1.01708542713568 1.01708542713568 1.01708542713568 1.01708542713568
1.01809045226131 .01809045226131  1.01809045226131 1.01809045226131 1.01809045226131
1.01909547738693 1.01909547738693 1.01909547738693 1.01909547738693 1.01909547738693];

Z=[0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000];

请注意 Z 对于每一列来说都是恒定的

答案1

您可以使用contourplot。首先,在 MATLAB 中准备数据:

[reshape(X,[],1), reshape(Y,[],1), reshape(Z,[],1)];

然后,你就可以在 TeX 中使用这些数据了:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xticklabel style={/pgf/number format/.cd, fixed, precision=2},
        yticklabel style={/pgf/number format/.cd, fixed, precision=3},
        ]
        \addplot[
            colormap={onlyblack}{gray(0cm)=(0); gray(1cm)=(0)},
            contour prepared,
            contour/contour label style={/pgf/number format/.cd, fixed, precision=2},
            contour/label distance={1000pt}, % use big number to get one label per contour
            ] table {
            0   1   0.05
            0.00499487214258387 1.00100502512563    0.05
            0.00703013931750997 1.00201005025126    0.05
            0.00856912164753604 1.00301507537688    0.05
            0.00984769541100846 1.00402010050251    0.05
            0.0109577332470996  1.00502512562814    0.05
            0.0119466084732432  1.00603015075377    0.05
            0.0128426154484001  1.00703517587940    0.05
            0.0136642899493110  1.00804020100503    0.05
            0.0144245776620953  1.00904522613065    0.05
            0.0151329564382696  1.01005025125628    0.05
            0.0157966212085941  1.01105527638191    0.05
            0.0164211931300526  1.01206030150754    0.05
            0.0170111676966756  1.01306532663317    0.05
            0.0175702105696051  1.01407035175879    0.05
            0.0181013600452389  1.01507537688442    0.05
            0.0186071698801841  1.01608040201005    0.05
            0.0190898126701751  1.01708542713568    0.05
            0.0195511563564558  1.01809045226131    0.05
            0.0199928219502558  1.01909547738693    0.05
            0   1   0.10
            0.0100271322719341  1.00100502512563    0.10
            0.0141123715001326  1.00201005025126    0.10
            0.0172011015018718  1.00301507537688    0.10
            0.0197669024060679  1.00402010050251    0.10
            0.0219942405774403  1.00502512562814    0.10
            0.0239782392419037  1.00603015075377    0.10
            0.0257757149277838  1.00703517587940    0.10
            0.0274238903416811  1.00804020100503    0.10
            0.0289487637697525  1.00904522613065    0.10
            0.0303693701768318  1.01005025125628    0.10
            0.0317001603416950  1.01105527638191    0.10
            0.0329524247496926  1.01206030150754    0.10
            0.0341351933703888  1.01306532663317    0.10
            0.0352558296774944  1.01407035175879    0.10
            0.0363204372087640  1.01507537688442    0.10
            0.0373341463673818  1.01608040201005    0.10
            0.0383013220178056  1.01708542713568    0.10
            0.0392257171221451  1.01809045226131    0.10
            0.0401105886622858  1.01909547738693    0.10
            0   1   0.15
            0.0151355841667174  1.00100502512563    0.15
            0.0213007419561194  1.00201005025126    0.15
            0.0259611298569260  1.00301507537688    0.15
            0.0298317587516411  1.00402010050251    0.15
            0.0331911596116199  1.00502512562814    0.15
            0.0361829739474490  1.00603015075377    0.15
            0.0388930053871466  1.00703517587940    0.15
            0.0413774721254582  1.00804020100503    0.15
            0.0436756433487295  1.00904522613065    0.15
            0.0458162730087464  1.01005025125628    0.15
            0.0478211921655991  1.01105527638191    0.15
            0.0497074590478197  1.01206030150754    0.15
            0.0514887177522871  1.01306532663317    0.15
            0.0531760952694321  1.01407035175879    0.15
            0.0547788154484420  1.01507537688442    0.15
            0.0563046321253931  1.01608040201005    0.15
            0.0577601426467341  1.01708542713568    0.15
            0.0591510199088859  1.01809045226131    0.15
            0.0604821874442227  1.01909547738693    0.15
            0   1   0.20
            0.0203619904285679  1.00100502512563    0.20
            0.0286533748405864  1.00201005025126    0.20
            0.0349192664533911  1.00301507537688    0.20
            0.0401218833508729  1.00402010050251    0.20
            0.0446361019206510  1.00502512562814    0.20
            0.0486552739640120  1.00603015075377    0.20
            0.0522949117805015  1.00703517587940    0.20
            0.0556307081325855  1.00804020100503    0.20
            0.0587155421791397  1.00904522613065    0.20
            0.0615881383770832  1.01005025125628    0.20
            0.0642779014739504  1.01105527638191    0.20
            0.0668078104510510  1.01206030150754    0.20
            0.0691962474012896  1.01306532663317    0.20
            0.0714582050315404  1.01407035175879    0.20
            0.0736061131758165  1.01507537688442    0.20
            0.0756504218986758  1.01608040201005    0.20
            0.0776000236025984  1.01708542713568    0.20
            0.0794625654482437  1.01809045226131    0.20
            0.0812446851052654  1.01909547738693    0.20
            0   1   0.25
            0.0257528910437245  1.00100502512563    0.25
            0.0362349750090093  1.00201005025126    0.25
            0.0441534216317338  1.00301507537688    0.25
            0.0507257254049430  1.00402010050251    0.25
            0.0564262963381876  1.00502512562814    0.25
            0.0614998638245181  1.00603015075377    0.25
            0.0660926587477192  1.00703517587940    0.25
            0.0703005193527485  1.00804020100503    0.25
            0.0741904098771546  1.00904522613065    0.25
            0.0778113778863288  1.01005025125628    0.25
            0.0812006730740997  1.01105527638191    0.25
            0.0843874098612964  1.01206030150754    0.25
            0.0873948821954542  1.01306532663317    0.25
            0.0902420919849960  1.01407035175879    0.25
            0.0929447953582426  1.01507537688442    0.25
            0.0955162408504069  1.01608040201005    0.25
            0.0979677038151599  1.01708542713568    0.25
            0.100308881996065   1.01809045226131    0.25
            0.102548194045946   1.01909547738693    0.25
        };
    \end{axis}
\end{tikzpicture}
\end{document}

得出以下结果:

结果

注意:我认为有一个拼写错误,并将您的其中一点从 更改.018090452261311.01809045226131

答案2

如果你使用包matlab2tikz由 Mathworks 提供,将最新的图导出为任意文件名:

matlab2tikz('my3d_plot.tikz');

请记住,您必须下载此功能(并将其保存在活动文件夹中以供评估)。此外,此功能为每个图生成一个名为的文件,my3d_plot-n.png其中n代表第 n 个图/子图。

3D 绘图

例如使用 matlab 绘图函数

imagesc(DATA);
colorbar('location','southoutside')

该函数具有设置颜色限制和颜色主题的选项。这些选项在 mathworks 的主页

保存存档

将文件保存'my3d_plot.tikz'在与处理过的 latex 文件相同的目录中,否则文件内的路径my3d_plot.tikz将指向错误的目录。

Latex 文件

类似下面的 MWE 应该可以实现这一点:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{graphicx}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}
\input{my3d_plot.tikz}
\end{document}

这回答了您的问题吗?还是有关要绘制的另一个特征的问题?

相关内容