Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gamesbyangelina/e0be22b725a25227f87c8b8199ea212a to your computer and use it in GitHub Desktop.
Save gamesbyangelina/e0be22b725a25227f87c8b8199ea212a to your computer and use it in GitHub Desktop.
%I forget if you need pgfplots or if I have it for another reason...
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\begin{tikzpicture}
% This is for a 3D plot. It assumes your data is in a file called data.txt, local to the tex file.
% Mine was formatted with one point per line, with each component separated by a single space like so:
% 1 0.5 3
% for x y and z components respectively. These are data points that you want to generate a surface out of.
% What the below does is, when you compile the LaTeX, it asks gnuplot/octave to triangulate your data
% so that tikz can plot that, since it's not able to just magically turn my random data into a surface.
% I installed gnuplot and octave using brew:
% brew install gnuplot
% brew install octave
% Important note: I had to add the option '-shell-escape' to my pdflatex call.
% In TexMaker you can go to preferences to see your pdflatex command, and add it there.
\begin{axis}
\addplot3 [patch, patch table={triangles.txt},
] shell {echo "data=dlmread('data.txt');
tri=delaunay(data(:,1), data(:,2));
dlmwrite('triangles.txt',tri-1,' ');
disp(data)" | octave --silent};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment