I want to plot the plane of intersection of the sphere $x^2+y^2+z^2=1$ and the plane $x+z=0$.
See the edit
I have tried to plot it with the help of https://tikz.net/parametric-sphere/.
My plane of intersection is not very clearly visible. Also I am not sure where this code is correctly developed.
Please help.
\documentclass[tikz,border=10mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{math}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1pt}
%
\begin{document}
%
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Parametric equations of the sphere
\tikzmath{function equis(\r,\p,\t) {return \r * sin(\p r) * cos(\t r);};}
\tikzmath{function ye(\r,\p,\t) {return \r * sin(\p r) * sin(\t r);};}
\tikzmath{function zeta(\r,\p,\t) {return \r * cos(\p r);};}
\pgfmathsetmacro{\tcero}{0.0}
\pgfmathsetmacro{\phiInit}{0.0}
\pgfmathsetmacro{\phiMid}{0.5*pi}
\pgfmathsetmacro{\phiEnd}{pi}
\pgfmathsetmacro{\thetaInit}{0.5*pi}
\pgfmathsetmacro{\thetaMid}{1.85*pi}
\pgfmathsetmacro{\thetaEnd}{2.5*pi}
%
\pgfmathsetmacro{\step}{0.02}
\pgfmathsetmacro{\next}{\tcero+0.5*\step}
\pgfmathsetmacro{\sig}{2.0*\step}
\pgfmathsetmacro{\radio}{2.0}
\pgfmathsetmacro{\sigP}{\phiMid+\step}
\pgfmathsetmacro{\sigPp}{\sigP+\step}
% Part of the z axis below the sphere
\draw[dashed] (0,0,-1.25*\radio) -- (0,0,-\radio);
% I start to draw the sphere from below
% Part of the sphere under the plane z = 0
\foreach \p in {\sigP,\sigPp,...,\phiEnd}{ \draw[gray,thick,opacity=0.15] plot[domain=\thetaInit:\thetaEnd,smooth,variable=\t] ({equis(\radio,\p,\t)},{ye(\radio,\p,\t)},{zeta(\radio,\p,\t)}); }
% Then I draw the part of the coordinate axis that is inside the sphere.
%%% Coordinate axis
\draw[thick,->] (0,0,0) -- (1.5*\radio,0,0) node [below left] {\footnotesize$x$};
\draw[dashed] (0,0,0) -- (-1.25*\radio,0,0);
\draw[thick,->] (0,0,0) -- (0,1.5*\radio,0) node [right] {\footnotesize$y$};
\draw[dashed] (0,0,0) -- (0,-1.25*\radio,0);
\draw[dashed] (0,0,0) -- (0,0,-\radio);
% As a reference, I draw a circumference at z = 0 (phi = pi / 2).
\draw[black,thick,opacity=0.25] plot[domain=0:2*pi,smooth,variable=\t] ({equis(\radio,\phiMid,\t)},{ye(\radio,\phiMid,\t)},{zeta(\radio,\phiMid,\t)});
% As a reference, I draw a circumference at x = 0 (theta = 0).
%\draw[red,opacity=0.25] plot[domain=0:2*pi,smooth,variable=\t] ({equis(\radio,\t,0)},{ye(\radio,\t,0)},{zeta(\radio,\t,0)});
% As a reference, I draw a circumference at y = 0 (theta = pi/2).
\draw[red,opacity=0.25] plot[domain=0:2*pi,smooth,variable=\t] ({equis(\radio,\t,\thetaInit)},{ye(\radio,\t,\thetaInit)},{zeta(\radio,\t,\thetaInit)});
%
% Now I draw the part of the sphere that is behind the axis
%
\foreach \p in {\step,\sig,...,\phiMid}{
\draw[gray,thick,opacity=0.25] plot[domain=\thetaInit:\thetaMid,smooth,variable=\t]
({equis(\radio,\p,\t)},{ye(\radio,\p,\t)},{zeta(\radio,\p,\t)});
}
% Z axis that is inside the sphere
% This part has to be in front of the rear part of the sphere
\draw[thick] (0,0,0) -- (0,0,\radio);
\draw[black,opacity=0.35,densely dotted] plot[domain=-3*pi/4:3*pi/4,smooth,variable=\t] ({equis(\radio,\t,\thetaInit)},{ye(\radio,\t,\thetaInit)},{zeta(\radio,\t,\thetaInit)});
%
% Sphere (the part that is in front of the z axis)
%
\foreach \p in {\step,\sig,...,\phiMid}{
\draw[gray,thick,opacity=0.1] plot[domain=\thetaMid:\thetaEnd,smooth,variable=\t]
({equis(\radio,\p,\t)},{ye(\radio,\p,\t)},{zeta(\radio,\p,\t)});
}
% Part of the z axis that is above the sphere
\draw[thick,->] (0,0,\radio) -- (0,0,1.5*\radio) node [above] {\footnotesize$z$};
\filldraw[
draw=black,%
fill=black!20,opacity=0.45%
] (2,2,-2)
-- (-2,2,-2)
-- (-2,-2,2)
-- (2,-2,2)
-- cycle;
% As a reference, I draw a circumference at y = 0 (theta = pi/2).
\draw[black,opacity=0.95] plot[domain=pi/2+pi/4:2*pi-pi/4,smooth,variable=\t] ({equis(\radio,\t,\thetaInit)},{ye(\radio,\t,\thetaInit)},{zeta(\radio,\t,\thetaInit)});
\end{tikzpicture}
\end{document}
Edited
**\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={35}{15},
unit vector ratio=1 1 1,
ticks = none,
ymin=-2.8,
ymax=0,
xmax=2.8,
xmin=0,
zmin=0,
zmax=2,
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west},
every axis y label/.style={at={(ticklabel* cs:0)},anchor=north east},
every axis z label/.style={at={(ticklabel* cs:1)},anchor=south},
x axis line style=-,
y axis line style=-,
z axis line style=-,
clip=false
]
\addplot3[name path=toppath,fill=gray, opacity=0.1, fill opacity=0.4,samples=2] (x/4,2,-x/4);
\addplot3[name path=botpath,fill=gray, opacity=0.1, fill opacity=0.4,samples=2] (x/4,-2,-x/4);
\addplot [gray] fill between[of=toppath and botpath];
\addplot3[surf,shader=interp,domain=0:360,y domain=-90:90,opacity=0.5,
colormap={bluewhite}{color=(blue) color=(blue!30)}] ({2*cos(y)*cos(x)},
{2*cos(y)*sin(x)},{2*sin(y)});
\addplot3[samples y=0,domain=0:360,smooth]({2*cos(x)}, {2*sin(x)},0);
\end{axis}
\end{tikzpicture}
\end{document}**
This code is working good but \addplot [gray] fill between[of=toppath and botpath];
creats a problem. The sphere slides to the left. Please help.