pgfplots で Voronoi 図を描く方法はありますか?

pgfplots で Voronoi 図を描く方法はありますか?

pgfplots でボロノイ図を描きたいのですが、残念ながら、期待どおりの図を描くことができません。 Matlab コマンドを使用して x 座標と y 座標を取得し、dat ファイルとして保存しました。 そのファイルでは、最初の列に x 座標を、2 番目の列に y 座標を保存しました。

Matlab出力: どのようにしたいか

pgfplots 出力: 現在の状態をスナップショットで表示します

どのように機能するかについて、誰かアイデアをお持ちですか?

コードの最小限の例:

\documentclass{standalone}

\usepackage{amsmath,amsfonts,amssymb} 
\usepackage{mathtools} 
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc} 
\usepackage{graphicx} 
\usepackage[svgnames]{xcolor} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\usepackage{tikz} 
\usetikzlibrary{positioning,fit,calc,shapes,arrows,external,3d,patterns,spy}

\usepackage{filecontents}

\begin{document}

\begin{filecontents*}{data.dat}
  -7.9265104e+00   3.6503989e-01
   4.3133971e-01   9.4062409e-01
  -7.9265104e+00   3.6503989e-01
   6.3976919e-02   5.4947497e-01
   6.3976919e-02   5.4947497e-01
   3.0293735e-01   6.5037024e-01
   3.6748619e-01   9.5786833e-02
   6.3976919e-02   5.4947497e-01
   3.0293735e-01   6.5037024e-01
   4.0645496e-01   8.2958752e-01
   4.9066479e-01   4.4410036e-01
   3.0293735e-01   6.5037024e-01
   3.6748619e-01   9.5786833e-02
   4.9244296e-01   2.3488102e-01
   4.9244296e-01   2.3488102e-01
   4.9066479e-01   4.4410036e-01
   4.9066479e-01   4.4410036e-01
   7.3082954e-01   5.1825327e-01
   1.8829507e+00   1.7053562e-01
   4.9244296e-01   2.3488102e-01
   4.3133971e-01   9.4062409e-01
   8.7230061e-01   2.0371867e+00
   4.0645496e-01   8.2958752e-01
   4.3133971e-01   9.4062409e-01
   6.6251849e-01   6.4842135e-01
   4.0645496e-01   8.2958752e-01
   6.9696115e-01   6.8938388e-01
   8.7230061e-01   2.0371867e+00
   7.3082954e-01   5.1825327e-01
   6.6251849e-01   6.4842135e-01
   1.8829507e+00   1.7053562e-01
   7.3082954e-01   5.1825327e-01
   6.6251849e-01   6.4842135e-01
   6.9696115e-01   6.8938388e-01
  -7.9265104e+00   3.6503989e-01
  -1.7371176e+01   8.6111447e-02
   3.6748619e-01   9.5786833e-02
  -6.0998602e-02  -1.3709259e+00
   1.8829507e+00   1.7053562e-01
   4.4291165e+00  -2.9045575e-01
   8.7230061e-01   2.0371867e+00
   1.8287612e+00   4.5227847e+00
   6.9696115e-01   6.8938388e-01
   1.9370861e+00   1.3452721e+00
\end{filecontents*}

\begin{tikzpicture}
\begin{axis}[x=3cm, y=3cm, z=0cm, view={0}{90}]
\addplot3 [color=blue, samples y=0] file {voronoi.dat}; 
\end{axis}
\end{tikzpicture}

\end{document}

ご協力いただきありがとうございます!!

答え1

ボロノイ図の個々の線分の間に空の線を追加して、線分が接続されないようにする必要があります。

ボロノイ図を描画するポイントの座標を含む次のファイル「points.dat」があるとします。

1   4
4   1
2   6
3   5
4   3
6   2

次に、Matlab または Octave を使用して次のように Voronoi 図を見つけることができます。

points = dlmread('points.dat');
[vx, vy] = voronoi(points(:,1), points(:,2));

これをPGFPlotsでプロットできるファイルに書き込むには、次のようにします。

fid = fopen('voronoi.dat', 'w');
fprintf(fid, '%f %f\n%f %f\n\n', [vx(:), vy(:)]');
fclose(fid);

PGFPlots では、次のようにプロットを作成できます。

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis equal image
]
\addplot [only marks, red] table {points.dat};
\addplot [no markers, update limits=false] table {voronoi.dat};
\end{axis}
\end{tikzpicture}
\end{document}

関連情報