TransWikia.com

PGFPlots keys for axes and plot styles only partially working

TeX - LaTeX Asked on July 27, 2021

I’m trying to plot different views of a 3D curve, but I’d like to define the axes and the plots’ style from the beginning; I haven’t been able to do this. Here’s the code and what I get:

documentclass[tikz,border=2mm]{standalone}

usepackage{pgfplots}

begin{document}

    begin{tikzpicture}[
        declare function ={
            ex(x)=cos(x)*sin(2*x);
            ye(x)=cos(x)*cos(2*x);
            ze(x)=sin(x);
        }
    ]
    pgfplotsset{
        every axis post/.append style={
            trig format plots=rad,
            scale=0.7
        }
        every axis plot/.append style={
            blue,
            domain=0:2*pi,
            samples=120 
        }
    }
    begin{axis}
    addplot3 ({ex(x)},{ye(x)},{ze(x)});
    end{axis}
    begin{axis}[xshift=7cm, view/h=120,view/v=90]
    addplot3 ({ex(x)},{ye(x)},{ze(x)});
    end{axis}
    end{tikzpicture}
end{document}

enter image description here

What I want is the following (obtained writing all the above options into every axis env. and every addplot macro):
enter image description here

The curve colour does take on, but not the rest of the options. I don’t really know if I’m using the right syntax for the keys; it clearly is correct syntax, because I can compile with no errors, but I am obviously missing something to get what I want and I can’t seem to find it in the manual. Thanks in advance!

One Answer

You forgot a comma between the two pgfplotsset parts (the every axis post part and the every axis plot part). Also you need an empty option set [] after addplot3 to trigger the general setting.

MWE:

documentclass{article}

usepackage{pgfplots}
pgfplotsset{compat=newest}
begin{document}

    begin{tikzpicture}[
        declare function ={
            ex(x)=cos(x)*sin(2*x);
            ye(x)=cos(x)*cos(2*x);
            ze(x)=sin(x);
        }
    ]
    pgfplotsset{
        every axis post/.append style={
            trig format plots=rad,
            scale=0.7
        },
        every axis plot/.append style={
            purple,
            domain=0:2*pi,
            samples=120 
        }
    }
    begin{axis}
    addplot3[] ({ex(x)},{ye(x)},{ze(x)});
    end{axis}
    begin{axis}[xshift=7cm, view/h=120,view/v=90]
    addplot3[] ({ex(x)},{ye(x)},{ze(x)});
    end{axis}
    end{tikzpicture}
end{document}

Result:

enter image description here

Correct answer by Marijn on July 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP