外部座標ファイルから3Dで滑らかな曲線をプロットする

外部座標ファイルから3Dで滑らかな曲線をプロットする

「xz.dat」のようなファイルに保存された、以前に計算された座標から 3D プロットを作成したいと思います。

これには次のデータが含まれます:

x z
0.5 0
0.54 0.01
0.58 0.01
0.62 0.02
0.66 0.03
0.7 0.03
0.74 0.04
0.78 0.05
etc.

最小限の動作例:

\documentclass{article}

\usepackage{datatool}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x={(210:3cm)},y={(330:3cm)},z={(90:3cm)}]
\draw (0,0,0)--(1,0,0);
\draw (0,0,0)--(0,1,0);
\draw (0,0,0)--(0,0,3);
\DTLsetseparator{ }
\DTLloaddb[noheader=false]{coordinates}{./xz.dat}
\DTLforeach*{coordinates}{\x=x,\z=z}{\filldraw (\x,0,\z) circle (0.02);}
\end{tikzpicture}

\end{document}

その結果は次のようになります:

ここに画像の説明を入力してください

これらの醜い押しつぶされた点の代わりに滑らかな線を使用して連続する座標を接続することは可能ですか?

「プロット ファイル」を使用してこれを行う方法はわかっていますが、これは 2D プロットに対してのみ機能します。

答え1

ファイルに 2 次元座標しかない場合でも、3D でプロットする方法は多数あります。 1 つの方法は、 で列を追加することですy=0。 もちろん、これを手動で行う必要はありません。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{data2.dat}
x z
0.5 0
0.54 0.01
0.58 0.01
0.62 0.02
0.66 0.03
0.7 0.03
0.74 0.04
0.78 0.05
\end{filecontents*}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.16}
\pgfplotstableset{
    create on use/new y/.style={
        create col/expr={0}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=-0.2,ymax=1]
\addplot3[no marks,smooth] table[x=x,y=new y,z=z] {data2.dat};
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

もちろんあなたできる使用しているフレームワークにスムーズ プロットも追加します。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{xz.dat}
x z
0.5 0
0.54 0.01
0.58 0.01
0.62 0.02
0.66 0.03
0.7 0.03
0.74 0.04
0.78 0.05
\end{filecontents*}
\usepackage{datatool}
\newcounter{mycoord}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x={(-25.98mm,-15mm)},y={(25.98mm,-15mm)},z={(0,30mm)}]
\draw (0,0,0)--(1,0,0);
\draw (0,0,0)--(0,1,0);
\draw (0,0,0)--(0,0,3);
\DTLsetseparator{ }
\DTLloaddb[noheader=false]{coordinates}{./xz.dat}
\DTLforeach*{coordinates}{\x=x,\z=z}{\stepcounter{mycoord}
\filldraw (\x,0,\z) coordinate(X-\themycoord) circle (0.02);}
\draw plot[smooth,samples at={1,...,\themycoord},variable=\x] (X-\x);
\end{tikzpicture}

\end{document}

使用データファイル(そして弾丸を取り除くと)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{filecontents}
\usepackage{datatool}
\newcounter{mycoord}
\usepackage{tikz}
%\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}[x={(-25.98mm,-15mm)},y={(25.98mm,-15mm)},z={(0,30mm)}]
\draw (0,0,0)--(1,0,0);
\draw (0,0,0)--(0,1,0);
\draw (0,0,0)--(0,0,3);
\DTLsetseparator{ }
\DTLloaddb[noheader=false]{coordinates}{./xz.dat}
\DTLforeach*{coordinates}{\x=x,\z=z}{\stepcounter{mycoord}
\path (\x,0,\z) coordinate(X-\themycoord);}
\draw plot[smooth,tension=0.5,samples at={1,...,\themycoord},variable=\x] (X-\x);
\end{tikzpicture}

\end{document}

ここに画像の説明を入力してください

小さな揺れは、平滑化によるものではなく、データによるものです。

関連情報