I want to plot a sequence of cones using tikz. My cones have arbitary coordinates that I calculated beforehand. For n cones, I have the coordinates of n+1 circles, each as a tuple of (depth, center, radius). The circles all lay in the X-Y plane.

I have something like this in mind:

enter image description here

I like the cross sections, as they provide an impression of depth. This is an illustration for an undergrad thesis, if you have suggestions feel free to comment. A cross section (in the X-Z plane) will be next to ist, with proper axes and units. This is just there to provide a proper 3D impression.

To explain a bit more: I don't want the code (after all, I did not give any coordinates..) but I saw this in the manual:

The second way of specifying points is to put them in an external file. Currently, the only format that TikZ allows is the following: Each line of the file should contain one line starting with two numbers, separated by a space. Anything following the two numbers on the line is ignored.

Now I would like to read arbitrary data from file. Something like (depth, center_x, center_y, radius) or so, whatever is easiest to read by tikz. I have not done this before and would be particularly interested in getting the values from a file into the foreach loop if tikz. I think I can handle the actual plotting from there.


1 Answer 1


With the use of the datatool package this code is what I ended up with:

        colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.8)}
        height=15cm, width=15cm,
        y domain=0:2*pi,
        samples y=32,
        scaled ticks=false,
        unit vector ratio=3 3 1]



        \DTLforeach*{coordinates}{\za=za, \xa=xa, \ra=ra, \zb=zb, \xb=xb, \rb=rb}{
            \addplot3[surf, shader=flat, draw=black, z buffer=sort, domain=\za:\zb]
            ({(\ra + (x-\za) * \rsc) * cos(deg(y)) + \xa + (x-\za) * \xsc},
            { (\ra + (x-\za) * \rsc) * sin(deg(y))},


This uses a custom made file with the proper data for each cone. That is bottom z-value, center and radius as well as upper z-value center and radius. (6 columns) It is important to use only 2 samples for the domain, as pdftex will take an eternity otherwise. (or run out of memory eventually)

So the picture looks like this: pgf plot

That picture apparently goes to the limits of tex and beyond. While I could compile a minimum example with pdftex, I could not integrate it into my thesis. pdftex runs out of memory. (that is, with --extra-mem-bot=200000000) Yes, this also happend when I used externalization. The solution was then to tell tikz to call luatex for generating the pictures:

\tikzset{external/system call={lualatex \tikzexternalcheckshellescape --interaction=nonstopmode --jobname "\image" "\texsource"}}

which works until now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .