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 bygnuplot
with 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.gnuplot
has already determined the projection of the 3d coordinates into 2d, all I need fromgnuplot
is to tell me which 3d coordinates it projected into 2d. This is dependent on the azimuth and elevation of the view, based on whichgnuplot
does z buffering. Unfortunately, I do not know how to get this information fromgnuplot
.z buffer
(for multiple plot objects) is built forpgfplots
? I believe this is the only feature that is really missing frompgfplots
and 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 ;).axis
(perhaps with empty tick labels).