pgfplots 从 csv 构建轮廓

pgfplots 从 csv 构建轮廓

我想绘制我所做的一些模拟的轮廓线。因此,我有一个csv包含计算数据的文件,我想用它pgfplots来绘制这些轮廓线。

我查看了互联网及其文档,pgfplots并创建了以下简单示例

\documentclass[12pt]{standalone} 
\usepackage[T1]{fontenc}
\usepackage{tikz}                       % 
\usepackage{pgfplots}                   %
    \pgfplotsset{compat=newest}         %


\begin{document}
\begin{tikzpicture} 
    \begin{axis}        
        \addplot3[mesh/rows=20,mesh/cols=10,
             contour gnuplot={number=3},
%            output point meta=rawz,
             ] 
            table[x=y, y=x, z=T, ignore chars={\#}, col sep=comma,
                    ] {./test.csv}; 
    \end{axis}  
\end{tikzpicture}
\end{document}

我的文件test.csv包含:

# x, y, T
1.000000000000000000e+00,1.000000000000000000e+00,6.665274928193408721e-01
2.000000000000000000e+00,1.000000000000000000e+00,6.663971023015621276e-01
3.000000000000000000e+00,1.000000000000000000e+00,6.664437620670988771e-01
4.000000000000000000e+00,1.000000000000000000e+00,6.665301707977002721e-01
5.000000000000000000e+00,1.000000000000000000e+00,6.666191243753081253e-01
6.000000000000000000e+00,1.000000000000000000e+00,6.667140894072094426e-01
7.000000000000000000e+00,1.000000000000000000e+00,6.668030901761194951e-01
8.000000000000000000e+00,1.000000000000000000e+00,6.668895764592672748e-01
9.000000000000000000e+00,1.000000000000000000e+00,6.669363119300035780e-01
1.000000000000000000e+01,1.000000000000000000e+00,6.668059134476984617e-01
1.000000000000000000e+00,2.000000000000000000e+00,6.664984000034479550e-01
2.000000000000000000e+00,2.000000000000000000e+00,6.663563233698642785e-01
3.000000000000000000e+00,2.000000000000000000e+00,6.664214191117951991e-01
4.000000000000000000e+00,2.000000000000000000e+00,6.665131018225954884e-01
5.000000000000000000e+00,2.000000000000000000e+00,6.666140120616599329e-01
6.000000000000000000e+00,2.000000000000000000e+00,6.667192060591138336e-01
7.000000000000000000e+00,2.000000000000000000e+00,6.668201621659066713e-01
8.000000000000000000e+00,2.000000000000000000e+00,6.669119206097180452e-01
9.000000000000000000e+00,2.000000000000000000e+00,6.669770941226786931e-01
1.000000000000000000e+01,2.000000000000000000e+00,6.668350157237450393e-01
1.000000000000000000e+00,3.000000000000000000e+00,6.664854791213135066e-01
2.000000000000000000e+00,3.000000000000000000e+00,6.663415913719938910e-01
3.000000000000000000e+00,3.000000000000000000e+00,6.664222063383633543e-01
4.000000000000000000e+00,3.000000000000000000e+00,6.665140801477354993e-01
5.000000000000000000e+00,3.000000000000000000e+00,6.666148761882257912e-01
6.000000000000000000e+00,3.000000000000000000e+00,6.667183640856011451e-01
7.000000000000000000e+00,3.000000000000000000e+00,6.668191978934161490e-01
8.000000000000000000e+00,3.000000000000000000e+00,6.669111359852449850e-01
9.000000000000000000e+00,3.000000000000000000e+00,6.669918243907704269e-01
1.000000000000000000e+01,3.000000000000000000e+00,6.668479455078759610e-01
1.000000000000000000e+00,4.000000000000000000e+00,6.664815006196560532e-01
2.000000000000000000e+00,4.000000000000000000e+00,6.663330228538590916e-01
3.000000000000000000e+00,4.000000000000000000e+00,6.664169300798881146e-01
4.000000000000000000e+00,4.000000000000000000e+00,6.665119589458776694e-01
5.000000000000000000e+00,4.000000000000000000e+00,6.666143422671383378e-01
6.000000000000000000e+00,4.000000000000000000e+00,6.667189113521675425e-01
7.000000000000000000e+00,4.000000000000000000e+00,6.668213283281555492e-01
8.000000000000000000e+00,4.000000000000000000e+00,6.669164154775901743e-01
9.000000000000000000e+00,4.000000000000000000e+00,6.670003945605174067e-01
1.000000000000000000e+01,4.000000000000000000e+00,6.668519314279444110e-01
1.000000000000000000e+00,5.000000000000000000e+00,6.664770000644588688e-01
2.000000000000000000e+00,5.000000000000000000e+00,6.663251033169389492e-01
3.000000000000000000e+00,5.000000000000000000e+00,6.664111506008371100e-01
4.000000000000000000e+00,5.000000000000000000e+00,6.665088727699410853e-01
5.000000000000000000e+00,5.000000000000000000e+00,6.666133511753929985e-01
6.000000000000000000e+00,5.000000000000000000e+00,6.667199070068153821e-01
7.000000000000000000e+00,5.000000000000000000e+00,6.668244175028308351e-01
8.000000000000000000e+00,5.000000000000000000e+00,6.669221964566964811e-01
9.000000000000000000e+00,5.000000000000000000e+00,6.670083158660570222e-01
1.000000000000000000e+01,5.000000000000000000e+00,6.668564335409302712e-01
1.000000000000000000e+00,6.000000000000000000e+00,6.664730997869784401e-01
2.000000000000000000e+00,6.000000000000000000e+00,6.663180845314861100e-01
3.000000000000000000e+00,6.000000000000000000e+00,6.664054966081143228e-01
4.000000000000000000e+00,6.000000000000000000e+00,6.665054530423857315e-01
5.000000000000000000e+00,6.000000000000000000e+00,6.666122244948706754e-01
6.000000000000000000e+00,6.000000000000000000e+00,6.667210326937413889e-01
7.000000000000000000e+00,6.000000000000000000e+00,6.668278363313814294e-01
8.000000000000000000e+00,6.000000000000000000e+00,6.669278502659713448e-01
9.000000000000000000e+00,6.000000000000000000e+00,6.670153355264032413e-01
1.000000000000000000e+01,6.000000000000000000e+00,6.668603341518074545e-01
1.000000000000000000e+00,7.000000000000000000e+00,6.664697463550552925e-01
2.000000000000000000e+00,7.000000000000000000e+00,6.663120196443859111e-01
3.000000000000000000e+00,7.000000000000000000e+00,6.664004262050575722e-01
4.000000000000000000e+00,7.000000000000000000e+00,6.665021952648533254e-01
5.000000000000000000e+00,7.000000000000000000e+00,6.666111123890067214e-01
6.000000000000000000e+00,7.000000000000000000e+00,6.667221413104018612e-01
7.000000000000000000e+00,7.000000000000000000e+00,6.668310914276506240e-01
8.000000000000000000e+00,7.000000000000000000e+00,6.669329195149436007e-01
9.000000000000000000e+00,7.000000000000000000e+00,6.670214007442626380e-01
1.000000000000000000e+01,7.000000000000000000e+00,6.668636878941709423e-01
1.000000000000000000e+00,8.000000000000000000e+00,6.664671553565268969e-01
2.000000000000000000e+00,8.000000000000000000e+00,6.663072476998228577e-01
3.000000000000000000e+00,8.000000000000000000e+00,6.663962705305201961e-01
4.000000000000000000e+00,8.000000000000000000e+00,6.664994244361608366e-01
5.000000000000000000e+00,8.000000000000000000e+00,6.666101447363657062e-01
6.000000000000000000e+00,8.000000000000000000e+00,6.667231048960070572e-01
7.000000000000000000e+00,8.000000000000000000e+00,6.668338591735474274e-01
8.000000000000000000e+00,8.000000000000000000e+00,6.669370737822977180e-01
9.000000000000000000e+00,8.000000000000000000e+00,6.670261728290619585e-01
1.000000000000000000e+01,8.000000000000000000e+00,6.668662792153110530e-01
1.000000000000000000e+00,9.000000000000000000e+00,6.664654603829183177e-01
2.000000000000000000e+00,9.000000000000000000e+00,6.663040583623929258e-01
3.000000000000000000e+00,9.000000000000000000e+00,6.663933804084154477e-01
4.000000000000000000e+00,9.000000000000000000e+00,6.664974447369693689e-01
5.000000000000000000e+00,9.000000000000000000e+00,6.666094420860504410e-01
6.000000000000000000e+00,9.000000000000000000e+00,6.667238041750613853e-01
7.000000000000000000e+00,9.000000000000000000e+00,6.668358363404600642e-01
8.000000000000000000e+00,9.000000000000000000e+00,6.669399627501244598e-01
9.000000000000000000e+00,9.000000000000000000e+00,6.670293622727493377e-01
1.000000000000000000e+01,9.000000000000000000e+00,6.668679744632736162e-01
1.000000000000000000e+00,1.000000000000000000e+01,6.664646443897686012e-01
2.000000000000000000e+00,1.000000000000000000e+01,6.663024890447618587e-01
3.000000000000000000e+00,1.000000000000000000e+01,6.663919082297593555e-01
4.000000000000000000e+00,1.000000000000000000e+01,6.664964158667143757e-01
5.000000000000000000e+00,1.000000000000000000e+01,6.666090728974014556e-01
6.000000000000000000e+00,1.000000000000000000e+01,6.667241714870277836e-01
7.000000000000000000e+00,1.000000000000000000e+01,6.668368638159816175e-01
8.000000000000000000e+00,1.000000000000000000e+01,6.669414343107787913e-01
9.000000000000000000e+00,1.000000000000000000e+01,6.670309316686268142e-01
1.000000000000000000e+01,1.000000000000000000e+01,6.668687906109909136e-01
1.000000000000000000e+00,1.100000000000000000e+01,6.664646443897686012e-01
2.000000000000000000e+00,1.100000000000000000e+01,6.663024890447619697e-01
3.000000000000000000e+00,1.100000000000000000e+01,6.663919082297594665e-01
4.000000000000000000e+00,1.100000000000000000e+01,6.664964158667143757e-01
5.000000000000000000e+00,1.100000000000000000e+01,6.666090728974012336e-01
6.000000000000000000e+00,1.100000000000000000e+01,6.667241714870280056e-01
7.000000000000000000e+00,1.100000000000000000e+01,6.668368638159817285e-01
8.000000000000000000e+00,1.100000000000000000e+01,6.669414343107786802e-01
9.000000000000000000e+00,1.100000000000000000e+01,6.670309316686269252e-01
1.000000000000000000e+01,1.100000000000000000e+01,6.668687906109908026e-01
1.000000000000000000e+00,1.200000000000000000e+01,6.664654603829183177e-01
2.000000000000000000e+00,1.200000000000000000e+01,6.663040583623929258e-01
3.000000000000000000e+00,1.200000000000000000e+01,6.663933804084154477e-01
4.000000000000000000e+00,1.200000000000000000e+01,6.664974447369693689e-01
5.000000000000000000e+00,1.200000000000000000e+01,6.666094420860504410e-01
6.000000000000000000e+00,1.200000000000000000e+01,6.667238041750613853e-01
7.000000000000000000e+00,1.200000000000000000e+01,6.668358363404600642e-01
8.000000000000000000e+00,1.200000000000000000e+01,6.669399627501244598e-01
9.000000000000000000e+00,1.200000000000000000e+01,6.670293622727493377e-01
1.000000000000000000e+01,1.200000000000000000e+01,6.668679744632737272e-01
1.000000000000000000e+00,1.300000000000000000e+01,6.664671553565266748e-01
2.000000000000000000e+00,1.300000000000000000e+01,6.663072476998227467e-01
3.000000000000000000e+00,1.300000000000000000e+01,6.663962705305200851e-01
4.000000000000000000e+00,1.300000000000000000e+01,6.664994244361608366e-01
5.000000000000000000e+00,1.300000000000000000e+01,6.666101447363657062e-01
6.000000000000000000e+00,1.300000000000000000e+01,6.667231048960070572e-01
7.000000000000000000e+00,1.300000000000000000e+01,6.668338591735474274e-01
8.000000000000000000e+00,1.300000000000000000e+01,6.669370737822977180e-01
9.000000000000000000e+00,1.300000000000000000e+01,6.670261728290620695e-01
1.000000000000000000e+01,1.300000000000000000e+01,6.668662792153110530e-01
1.000000000000000000e+00,1.400000000000000000e+01,6.664697463550550705e-01
2.000000000000000000e+00,1.400000000000000000e+01,6.663120196443860221e-01
3.000000000000000000e+00,1.400000000000000000e+01,6.664004262050573502e-01
4.000000000000000000e+00,1.400000000000000000e+01,6.665021952648533254e-01
5.000000000000000000e+00,1.400000000000000000e+01,6.666111123890067214e-01
6.000000000000000000e+00,1.400000000000000000e+01,6.667221413104018612e-01
7.000000000000000000e+00,1.400000000000000000e+01,6.668310914276506240e-01
8.000000000000000000e+00,1.400000000000000000e+01,6.669329195149436007e-01
9.000000000000000000e+00,1.400000000000000000e+01,6.670214007442625270e-01
1.000000000000000000e+01,1.400000000000000000e+01,6.668636878941707202e-01
1.000000000000000000e+00,1.500000000000000000e+01,6.664730997869783291e-01
2.000000000000000000e+00,1.500000000000000000e+01,6.663180845314862211e-01
3.000000000000000000e+00,1.500000000000000000e+01,6.664054966081143228e-01
4.000000000000000000e+00,1.500000000000000000e+01,6.665054530423855095e-01
5.000000000000000000e+00,1.500000000000000000e+01,6.666122244948704534e-01
6.000000000000000000e+00,1.500000000000000000e+01,6.667210326937413889e-01
7.000000000000000000e+00,1.500000000000000000e+01,6.668278363313813184e-01
8.000000000000000000e+00,1.500000000000000000e+01,6.669278502659714558e-01
9.000000000000000000e+00,1.500000000000000000e+01,6.670153355264032413e-01
1.000000000000000000e+01,1.500000000000000000e+01,6.668603341518071215e-01
1.000000000000000000e+00,1.600000000000000000e+01,6.664770000644588688e-01
2.000000000000000000e+00,1.600000000000000000e+01,6.663251033169390602e-01
3.000000000000000000e+00,1.600000000000000000e+01,6.664111506008372210e-01
4.000000000000000000e+00,1.600000000000000000e+01,6.665088727699408633e-01
5.000000000000000000e+00,1.600000000000000000e+01,6.666133511753928875e-01
6.000000000000000000e+00,1.600000000000000000e+01,6.667199070068152711e-01
7.000000000000000000e+00,1.600000000000000000e+01,6.668244175028308351e-01
8.000000000000000000e+00,1.600000000000000000e+01,6.669221964566965921e-01
9.000000000000000000e+00,1.600000000000000000e+01,6.670083158660571332e-01
1.000000000000000000e+01,1.600000000000000000e+01,6.668564335409303823e-01
1.000000000000000000e+00,1.700000000000000000e+01,6.664815006196560532e-01
2.000000000000000000e+00,1.700000000000000000e+01,6.663330228538593136e-01
3.000000000000000000e+00,1.700000000000000000e+01,6.664169300798881146e-01
4.000000000000000000e+00,1.700000000000000000e+01,6.665119589458776694e-01
5.000000000000000000e+00,1.700000000000000000e+01,6.666143422671384489e-01
6.000000000000000000e+00,1.700000000000000000e+01,6.667189113521674315e-01
7.000000000000000000e+00,1.700000000000000000e+01,6.668213283281555492e-01
8.000000000000000000e+00,1.700000000000000000e+01,6.669164154775902853e-01
9.000000000000000000e+00,1.700000000000000000e+01,6.670003945605175177e-01
1.000000000000000000e+01,1.700000000000000000e+01,6.668519314279444110e-01
1.000000000000000000e+00,1.800000000000000000e+01,6.664854791213135066e-01
2.000000000000000000e+00,1.800000000000000000e+01,6.663415913719941130e-01
3.000000000000000000e+00,1.800000000000000000e+01,6.664222063383633543e-01
4.000000000000000000e+00,1.800000000000000000e+01,6.665140801477353882e-01
5.000000000000000000e+00,1.800000000000000000e+01,6.666148761882257912e-01
6.000000000000000000e+00,1.800000000000000000e+01,6.667183640856010340e-01
7.000000000000000000e+00,1.800000000000000000e+01,6.668191978934161490e-01
8.000000000000000000e+00,1.800000000000000000e+01,6.669111359852450960e-01
9.000000000000000000e+00,1.800000000000000000e+01,6.669918243907705380e-01
1.000000000000000000e+01,1.800000000000000000e+01,6.668479455078759610e-01
1.000000000000000000e+00,1.900000000000000000e+01,6.664984000034481770e-01
2.000000000000000000e+00,1.900000000000000000e+01,6.663563233698643895e-01
3.000000000000000000e+00,1.900000000000000000e+01,6.664214191117953101e-01
4.000000000000000000e+00,1.900000000000000000e+01,6.665131018225954884e-01
5.000000000000000000e+00,1.900000000000000000e+01,6.666140120616598219e-01
6.000000000000000000e+00,1.900000000000000000e+01,6.667192060591137226e-01
7.000000000000000000e+00,1.900000000000000000e+01,6.668201621659067824e-01
8.000000000000000000e+00,1.900000000000000000e+01,6.669119206097181562e-01
9.000000000000000000e+00,1.900000000000000000e+01,6.669770941226791372e-01
1.000000000000000000e+01,1.900000000000000000e+01,6.668350157237451503e-01
1.000000000000000000e+00,2.000000000000000000e+01,6.665274928193409831e-01
2.000000000000000000e+00,2.000000000000000000e+01,6.663971023015621276e-01
3.000000000000000000e+00,2.000000000000000000e+01,6.664437620670989881e-01
4.000000000000000000e+00,2.000000000000000000e+01,6.665301707977003831e-01
5.000000000000000000e+00,2.000000000000000000e+01,6.666191243753081253e-01
6.000000000000000000e+00,2.000000000000000000e+01,6.667140894072093316e-01
7.000000000000000000e+00,2.000000000000000000e+01,6.668030901761193840e-01
8.000000000000000000e+00,2.000000000000000000e+01,6.668895764592674968e-01
9.000000000000000000e+00,2.000000000000000000e+01,6.669363119300038001e-01
1.000000000000000000e+01,2.000000000000000000e+01,6.668059134476987948e-01

我得到了一些图形结果但不幸的是它也返回一些错误: ! Package PGF Math Error: Could not parse input 'Surface' as a floating point number, sorry. The unreadable part was near 'Surface'..

我猜,我给出了错误的命令来构建图表。有很多使用解析函数的轮廓图示例,甚至包含预处理数据的文件示例,但关于 csv 文件中的原始数据的示例并不多。

那么,如何从 csv 文件构建轮廓图?

答案1

的使用ignore chars={\#}非常“脆弱”,我无法忽略它(其他人可能可以),所以对我来说,最简单的方法是完全忽略注释行,并假装注释仅用于提示标题值

因此我们只需要对该行进行一点改动

\documentclass[12pt]{standalone} 
\usepackage[T1]{fontenc}
\usepackage{tikz}                       % 
\usepackage{pgfplots}                   %
    \pgfplotsset{compat=newest}         %

\begin{document}
\begin{tikzpicture} 
    \begin{axis}        
        \addplot3[mesh/rows=20,mesh/cols=10,
             contour gnuplot={number=3},
%            output point meta=rawz,
             ]  

下面我们忽略标题注释,通过反转 0 和 1 的索引顺序来交换 x 和 y(如预期的那样?)

            table[header=false,x index={1},y index={0},z index={2},col sep=comma] {./test.csv}; 
        \end{axis}  
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容