我想在单纯形内绘制函数,但每次以通常的二维绘图方式添加函数时都会出错。如何添加两个变量的函数,例如 x^2+y^2 =0.5,以下是示例:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{ifthen}
\begin{document}
\tdplotsetmaincoords{80}{130}
\begin{tikzpicture}[scale=2,tdplot_main_coords]
\coordinate (O) at (1,0,0);
\coordinate (P) at (0,1,0);
\coordinate (Q) at (0,0,1);
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[thick,color=red] (O) -- (P);
\draw[thick, color=red] (P) -- (Q);
\draw[thick, color=red] (Q) -- (O);
\end{tikzpicture}
\end{document}
更新 我尝试了不同的代码,但仍然无法写入两个不同变量的函数:
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view/h=135,
axis lines=center,
xmax=1.5,
ymax=1.5,
zmax=1.5,
ytick={1},
xlabel={$x_{1}$},
ylabel={$x_{2}$},
zlabel={$x_{3}$},
]
\addplot3[patch,blue!70!black!50,forget plot]
coordinates
{
(1,0,0)
(0,1,0)
(0,0,1)
};
\addplot3[no markers,red!90!black]
coordinates
{
(0.25,0.1,0.45)
(0.2,0.1,0.4)
(0.24,0.36,0.4)
(0.16,0.32,0.62)
(0.12,0.3,0.58)
(0.1,0.26,0.64)
};
\addplot3[domain=0:2, red, thick] {x^2+y^2};
\node[fill=red!90!black,inner sep=1pt,circle,label={180:$Y$}]
at (axis cs:0.1,0.26,0.64) {};
\end{axis}
\end{tikzpicture}
\end{document}
例如,这里我输入了 x^2,它有效,但我想输入 y^2,但它无效,或者 z^2.. 或任何两个变量的函数。注意:x^2 实际上不是我想要的图形,但我只是想让代码适用于任何两个变量的函数
更新 2我忘了使用 \addplot3,它现在似乎可以工作了。