插入网格数据以获得三维光滑表面

插入网格数据以获得三维光滑表面

我用这个代码

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\pgfplotsset{
ytick={0,0.2,...,1},
xtick={0,0.2,...,1},
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmajorgrids=true,
ymajorgrids=true,
major grid style={dashed},
}

\begin{tikzpicture}
    \begin{axis}[view/h=45,xmin=0,xmax=1,ymin=0,ymax=1,colorbar horizontal, xlabel style={sloped}, ylabel style={sloped}, colorbar style={xlabel=$z$, xlabel style={at={(axis description cs:0.5,-1)}}}]
        \addplot3[surf,shader=faceted interp] table [col sep=comma] {scatter.csv};
    \end{axis}
\end{tikzpicture}

\end{document}

有了这个scatter.csv

0.000000,0.000000,50
0.000000,0.020110,2
0.000000,0.021307,0
0.000000,0.250000,5
0.000000,0.333333,3
0.000000,0.500000,22
0.000000,1.000000,1

0.000300,0.000000,2
0.000300,0.020110,0
0.000300,0.021307,0
0.000300,0.250000,0
0.000300,0.333333,0
0.000300,0.500000,0
0.000300,1.000000,0

0.001908,0.000000,2
0.001908,0.020110,0
0.001908,0.021307,0
0.001908,0.250000,0
0.001908,0.333333,0
0.001908,0.500000,0
0.001908,1.000000,0

0.003472,0.000000,2
0.003472,0.020110,0
0.003472,0.021307,0
0.003472,0.250000,0
0.003472,0.333333,0
0.003472,0.500000,0
0.003472,1.000000,0

0.010204,0.000000,3
0.010204,0.020110,0
0.010204,0.021307,0
0.010204,0.250000,0
0.010204,0.333333,0
0.010204,0.500000,0
0.010204,1.000000,0

0.028409,0.000000,2
0.028409,0.020110,0
0.028409,0.021307,0
0.028409,0.250000,0
0.028409,0.333333,0
0.028409,0.500000,0
0.028409,1.000000,0

0.035714,0.000000,0
0.035714,0.020110,0
0.035714,0.021307,2
0.035714,0.250000,0
0.035714,0.333333,0
0.035714,0.500000,0
0.035714,1.000000,0

0.045455,0.000000,1
0.045455,0.020110,0
0.045455,0.021307,0
0.045455,0.250000,0
0.045455,0.333333,0
0.045455,0.500000,2
0.045455,1.000000,0

0.083154,0.000000,0
0.083154,0.020110,0
0.083154,0.021307,0
0.083154,0.250000,0
0.083154,0.333333,0
0.083154,0.500000,2
0.083154,1.000000,0

0.092784,0.000000,0
0.092784,0.020110,0
0.092784,0.021307,0
0.092784,0.250000,0
0.092784,0.333333,0
0.092784,0.500000,2
0.092784,1.000000,0

0.119578,0.000000,2
0.119578,0.020110,0
0.119578,0.021307,0
0.119578,0.250000,0
0.119578,0.333333,0
0.119578,0.500000,0
0.119578,1.000000,0

1.000000,0.000000,1
1.000000,0.020110,0
1.000000,0.021307,0
1.000000,0.250000,0
1.000000,0.333333,0
1.000000,0.500000,4
1.000000,1.000000,68

我得到以下三维图

在此处输入图片描述

这是正确的,但很丑。我知道这是由我的数据点的分布(不均匀)造成的。我怎样才能获得光滑的表面?

答案1

的内置功能pgfplots允许将数据矩阵可视化为三角曲面片或双线性曲面片(后者使用patch type=bilinear)。

给定合适的数据输入,它还允许双二次和双三次(即平滑)补丁。但是,该数据输入要复杂得多。此方法的简要概述如下使用程序图形创建贝塞尔曲面。但请注意,此方法不适用于您的输入表;数据格式需要丰富和重组。

为了提高图片质量,您有两种选择:(a)增加绘图的采样密度并坚持使用分段线性/分段双线性着色或(b)保持采样密度,但通过某些高级外部工具将每个补丁的阶数增加为双二次或双三次并将其导入pgfplots

如果问题是:“如何在保留输入数据的同时获得平滑的表面”,答案是:pgfplots最多提供patch type=bilinear(结合\usepgfplotslibrary{patchplots}):

在此处输入图片描述

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.11}

\begin{document}

\pgfplotsset{
ytick={0,0.2,...,1},
xtick={0,0.2,...,1},
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmajorgrids=true,
ymajorgrids=true,
major grid style={dashed},
}

\begin{tikzpicture}
    \begin{axis}[view/h=45,xmin=0,xmax=1,ymin=0,ymax=1,colorbar horizontal, xlabel style={sloped}, ylabel style={sloped}, colorbar style={xlabel=$z$, xlabel style={at={(axis description cs:0.5,-1)}}}]
        \addplot3[surf,
            patch type=bilinear,
            shader=faceted interp] table [col sep=comma] {
0.000000,0.000000,50
0.000000,0.020110,2
0.000000,0.021307,0
0.000000,0.250000,5
0.000000,0.333333,3
0.000000,0.500000,22
0.000000,1.000000,1

0.000300,0.000000,2
0.000300,0.020110,0
0.000300,0.021307,0
0.000300,0.250000,0
0.000300,0.333333,0
0.000300,0.500000,0
0.000300,1.000000,0

0.001908,0.000000,2
0.001908,0.020110,0
0.001908,0.021307,0
0.001908,0.250000,0
0.001908,0.333333,0
0.001908,0.500000,0
0.001908,1.000000,0

0.003472,0.000000,2
0.003472,0.020110,0
0.003472,0.021307,0
0.003472,0.250000,0
0.003472,0.333333,0
0.003472,0.500000,0
0.003472,1.000000,0

0.010204,0.000000,3
0.010204,0.020110,0
0.010204,0.021307,0
0.010204,0.250000,0
0.010204,0.333333,0
0.010204,0.500000,0
0.010204,1.000000,0

0.028409,0.000000,2
0.028409,0.020110,0
0.028409,0.021307,0
0.028409,0.250000,0
0.028409,0.333333,0
0.028409,0.500000,0
0.028409,1.000000,0

0.035714,0.000000,0
0.035714,0.020110,0
0.035714,0.021307,2
0.035714,0.250000,0
0.035714,0.333333,0
0.035714,0.500000,0
0.035714,1.000000,0

0.045455,0.000000,1
0.045455,0.020110,0
0.045455,0.021307,0
0.045455,0.250000,0
0.045455,0.333333,0
0.045455,0.500000,2
0.045455,1.000000,0

0.083154,0.000000,0
0.083154,0.020110,0
0.083154,0.021307,0
0.083154,0.250000,0
0.083154,0.333333,0
0.083154,0.500000,2
0.083154,1.000000,0

0.092784,0.000000,0
0.092784,0.020110,0
0.092784,0.021307,0
0.092784,0.250000,0
0.092784,0.333333,0
0.092784,0.500000,2
0.092784,1.000000,0

0.119578,0.000000,2
0.119578,0.020110,0
0.119578,0.021307,0
0.119578,0.250000,0
0.119578,0.333333,0
0.119578,0.500000,0
0.119578,1.000000,0

1.000000,0.000000,1
1.000000,0.020110,0
1.000000,0.021307,0
1.000000,0.250000,0
1.000000,0.333333,0
1.000000,0.500000,4
1.000000,1.000000,68
        };
    \end{axis}
\end{tikzpicture}

\end{document}

请注意,您的屏幕截图显示的是过时/不正确的 PDF 查看器。您在问题中输入的最小工作示例的正确输出是

在此处输入图片描述

您可以使用 Acrobat Reader 来验证这一点。我知道一些旧的 PDF 查看器对阴影的支持很差。我猜您的查看器是xpdf或 的某个变体libpoppler。有更新的版本可以正确显示这些阴影。我建议升级到更新的查看器。

相关内容