
我正在嘗試繪製 3D 曲線的不同視圖,但我想從一開始就定義軸和繪圖的樣式;我沒能做到這一點。這是程式碼和我得到的內容:
\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}
我想要的是以下內容(將上述所有選項寫入每個axis
環境和每個\addplot
巨集中):
曲線顏色確實出現,但其餘選項不出現。我真的不知道我是否使用了正確的鍵語法;它顯然是正確的語法,因為我可以毫無錯誤地進行編譯,但我顯然缺少一些東西來獲得我想要的東西,而且我似乎無法在手冊中找到它。先致謝!
答案1
pgfplotsset
您忘記了兩個部分(every axis post
部分和every axis plot
部分)之間的逗號。此外,您還需要[]
在後面設定一個空選項\addplot3
來觸發常規設定。
微量元素:
\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}
結果: