如何使用 pgfplots 准备 3D 曲面图的坐标

如何使用 pgfplots 准备 3D 曲面图的坐标

我正在尝试使用 pgfplots 在 3 维上绘制帕累托前沿。但是,尽管我期望出现一个漂亮的表面(因为它是帕累托前沿),但 pgfplots 尚未产生我想要的结果。

我感觉我需要(以某种方式)对我的坐标集合进行排序或将其转换为矩阵。但是,我在 pgfplots 手册中找不到有关此内容的任何信息。我​​知道有些图不需要矩阵(MWE fi 中的图),但这里的顺序确实很重要。

任何有关如何预处理我的数据的帮助都将不胜感激。

到目前为止,这是我使用的实际数据作为 MWE 所获得的最佳结果。

\documentclass[tikz]{standalone}
\usepackage{pgfplots}       % Charts in LaTeX, or, even better, in TikZ!!!
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[title={3D plot of Pareto front},
      width=.75\textwidth,
      xlabel={Precision},
      ylabel={Replay Fitness},
      zlabel={Generalization},
      view/h=-60,
    ]
    \addplot3+
    [patch,patch type=biquadratic, shader=faceted interp,patch to triangles,patch refines=3,mark=none] 
      file {data.txt};
    \end{axis}
  \end{tikzpicture}
  \caption{3D plot of Pareto front.}
\end{figure} 
\end{document} 

其结果是:

当前绘图结果

data.txt 内容如下:

1.000000 0.419383 0.968689
1.000000 0.592352 0.968670
1.000000 0.746263 0.968656
1.000000 0.867638 0.968467
0.920836 0.968086 0.968154
0.639138 0.968335 0.968148
0.834616 0.972716 0.968135
1.000000 0.959536 0.968100
0.925890 0.968086 0.968100
0.843374 0.972253 0.968100
0.624724 0.994175 0.965305
0.592214 0.998805 0.965289
0.753481 0.993391 0.965285
0.740626 0.993727 0.965278
0.871820 0.993727 0.965277
0.785909 0.994025 0.965277
0.953650 0.993698 0.965273
0.805640 0.998855 0.965273
0.523510 0.999667 0.965029
0.564376 0.999738 0.965023
0.711429 0.999266 0.965001
0.879139 0.993727 0.964992
0.723471 0.999266 0.964992
0.659416 0.999528 0.964697
0.668084 0.999423 0.964666
0.677879 0.999423 0.964656
1.000000 0.979768 0.964530
0.450423 0.999843 0.954335
0.528080 0.999843 0.952593
0.843906 0.996905 0.950163
0.854689 0.993826 0.945594
0.738809 0.999266 0.945594
0.707177 0.999723 0.943947
0.544764 0.999778 0.943905
0.884787 0.993826 0.942041
0.757883 0.999266 0.942041
0.784359 0.999108 0.940599
0.604841 0.999778 0.939674
0.810387 0.998584 0.939038
0.482403 1.000000 0.938628
0.716901 0.999723 0.936281
0.559973 1.000000 0.935840
0.818384 0.997063 0.934713
0.725681 0.999557 0.926138
0.957708 0.980431 0.925825
0.819722 0.997010 0.921207
0.749411 0.999557 0.920465
0.596822 1.000000 0.917863
0.737162 1.000000 0.916918
0.824987 0.997010 0.899531

更新 1:

我已经发现一个答案回到相关问题,我试图让 GNUplot 对我的数据进行三角剖分,以便获得一个平面。但是,我认为我的问题仍然有效,因为我不需要从三个轴的最小值和最大值获得一个完整的平面,而只需要一个连接我的具体观察的表面。

答案1

我设法让更新 1 中提到的方法发挥作用(虽然 GNUplot 已添加到 Windows 路径中,但 Latex 找不到它……)。我希望此更新能帮助某些人,让我花费的时间对人类社会有所裨益。新数据集上的结果如下所示

正确的帕累托前沿可视化

代码:

\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[%title={3D plot of Pareto front},
      width=.75\textwidth,
      ylabel={Precision},
      xlabel={Replay Fitness},
      zlabel={Generalization},
        view={75}{40},
    ]
       \addplot3 [surf, faceted color=blue] gnuplot [raw gnuplot]{
        cd "MY_MAIN_LATEX_DIR";
        set dgrid3d 30,30 qnorm 2;
        splot "data.txt"; %
        };
        \addplot3[only marks]
        file data.txt};
    \end{axis}
  \end{tikzpicture}
  \caption{3D plot of the Pareto front of candidates with perfect simplicity.}
  \label{fig:caseStudies_runExNoise_pareto_graph_Of_allG}
\end{figure}
\end{document}

在这个新获得的数据集上:

1.0000  0.9277  0.8012
0.5924  0.9687  1.0000
0.9994  0.9647  0.6681
0.9995  0.7661  0.9190
0.9991  0.9038  0.9407
0.9937  0.9653  0.9291
0.9937  0.9653  0.9537
0.9934  0.9653  0.7535
0.9996  0.5437  0.9143
0.9987  0.9605  0.9275
0.9993  0.9509  0.7700
0.9994  0.8930  0.8912
0.9997  0.9041  0.8838
1.0000  0.9386  0.4824
0.9996  0.6511  0.9107
1.0000  0.8804  0.8510
0.9994  0.7355  0.9190
0.9987  0.9599  0.9906
0.9993  0.9650  0.7114
0.9996  0.5518  0.9120
0.9993  0.9172  0.8409
0.9997  0.9172  0.8048
0.9998  0.9084  0.8473
0.9991  0.9410  0.9288
0.9989  0.9653  0.8056
0.9996  0.6121  0.9120
0.9998  0.9543  0.4624
0.9993  0.9099  0.9357
0.9996  0.5441  0.9122
0.9993  0.8683  0.9381
0.9999  0.8459  0.8965
0.9993  0.9148  0.8778
0.9997  0.8523  0.8923
0.4194  0.9687  1.0000
0.9937  0.9650  0.9981
0.9937  0.9653  0.8718
0.9996  0.9122  0.8591
0.9996  0.7516  0.9079
0.9681  0.9682  0.9208
0.9993  0.8842  0.9074
0.9998  0.9439  0.5451
1.0000  0.7993  0.9031
0.9996  0.7238  0.9105
0.9993  0.8773  0.9374
1.0000  0.8610  0.8802
1.0000  0.9291  0.7801
0.9992  0.8981  0.9921
0.9990  0.9336  0.9340

相关内容