Although PGFplots is the perfect tool for many depictions, it unfortunately does not have a properly working z buffer for intersecting surfaces (at this time, 10-09-2015). I'm trying to overcome this problem by plotting in gnuplot with set terminal tikz and then putting the plots in a PGFplots axis environment. I cannot seem to manage the latter, though.
from http://gnuplot.sourceforge.net/demo_5.0/surface2.9.gnu as an example, where I changed the terminal to tikz:
set terminal tikz standalone
set output 'main.tex'
set dummy u, v
set key bmargin center horizontal Right noreverse enhanced autotitle nobox
set parametric
set view 50, 30, 1, 1
set isosamples 50, 20
set hidden3d back offset 1 trianglepattern 3 undefined 1 altdiagonal bentover
set style data lines
set ticslevel 0
set title "Interlocking Tori"
set urange [ -3.14159 : 3.14159 ] noreverse nowriteback
set vrange [ -3.14159 : 3.14159 ] noreverse nowriteback
splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with lines, 1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with lines
The resulting tex file main.tex has the following content
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8x]{inputenc}
\usepackage{gnuplot-lua-tikz}
\pagestyle{empty}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{\gpbboxborder}
\begin{document}
\begin{tikzpicture}[gnuplot]
%% generated with GNUPLOT 4.6p5 (Lua 5.1; terminal rev. 99, script rev. 100)
%% Thu 10 Sep 2015 01:40:19 PM CEST
\path (0.000,0.000) rectangle (12.500,8.750);
\gpcolor{color=gp lt color border}
\node[gp node center] at (6.250,8.163) {Interlocking Tori};
\gpcolor{color=gp lt color 0}
\gpsetlinetype{gp lt plot 0}
\gpsetlinewidth{1.00}
\draw[gp path] (6.400,6.200)--(6.110,6.207);
(...A lot of \draw[gp path] commands...)
%% coordinates of the plot area
\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.800cm}{1.387cm}}{\pgfpoint{10.700cm}{7.979cm}}
\end{tikzpicture}
%% gnuplot variables
\end{document}
from which it is clear that there is no use of a PGFplots axis environment.
Compiling with lualatex -shell-escape main.tex gives
, which 'solves' the z buffer problem. But how do I get these drawings in a nice PGFplots axis enviroment?





\includegraphics{gnuplotresult.pdf}and typesetting the tikz file generated by gnuplot. What you need to is to couple the existing 2d projection generated bygnuplotwith the axis ofpgfplots; and that is a use-case of\addplot3 graphics. I suppose the associated sections in the reference manual are the best at hand; the key idea is to map a couple of 2d locations to their 3d coordinates and tell that to pgfplots. – Christian Feuersänger Sep 11 '15 at 20:18gnuplothas already determined the projection of the 3d coordinates into 2d, all I need fromgnuplotis to tell me which 3d coordinates it projected into 2d. This is dependent on the azimuth and elevation of the view, based on whichgnuplotdoes z buffering. Unfortunately, I do not know how to get this information fromgnuplot. – Adriaan Sep 14 '15 at 07:25z buffer(for multiple plot objects) is built forpgfplots? I believe this is the only feature that is really missing frompgfplotsand withholds it from being the perfect tool for making graphs inLaTeX, not only in 2D, but then also in 3D. It would solve this particular Stack Exchange question, and many many others. Perhaps I could even help you out. You have my contact data, so let me know ;). – Adriaan Sep 14 '15 at 07:32axis(perhaps with empty tick labels). – Christian Feuersänger Sep 14 '15 at 21:33z bufferwould be cool. And I fear that it is extremely expensive in terms of programming effort when done in pgfplots, even I would do it in itslua backend. But thanks for the implied praise. If you want to help out, we should chat (by phone?) eventually. But honestly, I fear it would need to dig quite deep into pgfplots if it should be done efficiently. – Christian Feuersänger Sep 14 '15 at 21:36asymptoteworked much better for me. – Derek Sep 27 '16 at 23:13