# Surface of sphere split into strips using TikZ

I am trying to reproduce this diagram:

This is my attempt so far using code from Sphere Segments in PGF/TIKZ

Can anyone help make it match my desired result? I'm having trouble getting the perspective correct.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\usepackage{xxcolor}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
\makeatother

% Style to set TikZ camera angle, like PGFPlots view
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}

% Styles to plot only points that are before or behind the sphere.
\pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
}}
\pgfplotsset{only background/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
}}

% Automatically plot transparent lines in background and solid lines in foreground
}

\newcommand{\ViewAzimuth}{-10}
\newcommand{\ViewElevation}{55}

\begin{document}
\begin{tikzpicture}[rotate=-90]
% Compute camera unit vector for calculating depth
\pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
\pgfmathsetmacro{\DeltaPhi}{10}
% Draw a nice looking sphere
\begin{scope}
\clip[name path global=sphere] (0,0) circle (\Radius*1cm);
\begin{scope}[transform canvas={rotate=-200}]
\end{scope}
\end{scope}
\begin{axis}[clip=false,
hide axis,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% draw axis by hand
\draw[dashed,name intersections={of=xaxis and sphere,by=X}]
(0,0,0) --  (X);
\draw[dashed,name intersections={of=yaxis and sphere,by=Y}]
(0,0,0) --  (Y);
% Plot the surfaces

%draw the grand circle and equator
% continue drawing axes
node[left,rotate=90]{$x_3$};
\draw[-latex]   (X) --  (0,1.1*\Radius,0) coordinate (Xend)
node[above,rotate=90]{$x_2$};
\draw[-latex]   (Y) --  (0,0,1.4*\Radius) coordinate (Yend)
node[above,rotate=90]{$x_1$};

\end{axis}
\end{tikzpicture}
\end{document}

• Nice question withe all needed information. Thats good style. +1 – Bobyandbob Oct 21 '19 at 17:21

I just permuted the coordinates to get rid of the rotate=90. Thus the azimuth and elevation recover their original meaning. Then an azimuth of 30 and an elevation of 25 seems to come close to your screen shot.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{xxcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

% Style to set TikZ camera angle, like PGFPlots view
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}

% Styles to plot only points that are before or behind the sphere.
\pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
}}
\pgfplotsset{only background/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
}}

% Automatically plot transparent lines in background and solid lines in foreground
}

\newcommand{\ViewAzimuth}{30}
\newcommand{\ViewElevation}{25}

\begin{document}
\begin{tikzpicture}[>=stealth]
% Compute camera unit vector for calculating depth
\pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
\pgfmathsetmacro{\DeltaPhi}{10}
\begin{axis}[clip=false,hide axis,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\begin{axis}[clip=false,hide axis,xshift=12cm,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\begin{axis}[clip=false,hide axis,xshift=24cm,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\end{tikzpicture}

\end{document}


Or an azimuth of 40 and an elevation of 15.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{xxcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

% Style to set TikZ camera angle, like PGFPlots view
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}

% Styles to plot only points that are before or behind the sphere.
\pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
}}
\pgfplotsset{only background/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
}}

% Automatically plot transparent lines in background and solid lines in foreground
}

\newcommand{\ViewAzimuth}{40}
\newcommand{\ViewElevation}{15}

\begin{document}
\begin{tikzpicture}[>=stealth]
% Compute camera unit vector for calculating depth
\pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
\pgfmathsetmacro{\DeltaPhi}{10}
\begin{axis}[clip=false,hide axis,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\begin{axis}[clip=false,hide axis,xshift=12cm,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\begin{axis}[clip=false,hide axis,xshift=24cm,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\addplot3[only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0) -- (0,2,0) node[above right] {$x$};
\draw[thick,->]  (0,0,0) -- (0,0,2) node[above] {$y$};
\end{axis}
\end{tikzpicture}

\end{document}


Only you can decide what looks really good. This answer provides you with means of adjusting the view in the usual way.

ADDENDUM: It seems that wrapping a macro around \addplot can have interesting side effects. Somethings transformations are applied twice. One may then undo the excess transformations unless there is a more systematic way.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{xxcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

% Style to set TikZ camera angle, like PGFPlots view
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}

% Styles to plot only points that are before or behind the sphere.
\pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
}}
\pgfplotsset{only background/.style={
restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
}}

% Automatically plot transparent lines in background and solid lines in foreground
}

\newcommand{\ViewAzimuth}{40}
\newcommand{\ViewElevation}{15}
\newcommand\RingPlot[2][]{
\begin{axis}[#1,clip=false,hide axis,set layers,
view={\ViewAzimuth}{\ViewElevation},     % Set view angle
every axis plot/.style={very thin},
disabledatascaling,                      % Align PGFPlots coordinates with TikZ
anchor=origin,                           % Align PGFPlots coordinates with TikZ
viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
]
\draw[thick,->]  (\Radius,0,0) -- (\Radius+2,0,0) node[right] {$\theta=0^\circ$};
\draw[thick,->]  (0,\Radius,0) -- (0,\Radius+2,0) node[above right] {$\phi=0^\circ$};
\draw[thick,->]  (0,0,\Radius) -- (0,0,\Radius+2) node[above] {$\phi=90^\circ$};
\draw[thick,->]  (0,0.5,0) -- (0,2,0) node[above right] {$x$};
\addplot3[mark layer=axis background,on layer=axis background,only marks,mark=cube*,cube/size x=10pt,cube/size y=10pt,cube/size z=10pt] coordinates {(0,0,0)};
\draw[thick,->]  (0.5,0,0) -- (2,0,0) node[right] {$z$};
\draw[thick,->]  (0,0,0.5) -- (0,0,2) node[above] {$y$};
#2,surf,opacity=0.6]
\end{axis}}
\begin{document}
\begin{tikzpicture}[>=stealth]
% Compute camera unit vector for calculating depth
\pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
\pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
\pgfmathsetmacro{\DeltaPhi}{10}
\RingPlot{domain y=7.5*\DeltaPhi:9*\DeltaPhi}
\begin{scope}[xshift=12cm]
\RingPlot{domain y=6*\DeltaPhi:7.5*\DeltaPhi,xshift=-6cm}
\end{scope}
\begin{scope}[xshift=24cm]
\RingPlot{domain y=4.5*\DeltaPhi:6*\DeltaPhi}
\end{scope}
\end{tikzpicture}

\end{document}


One would think that one does not need xshift=-6cm in the second plot. But if one omits it, the result is wrong.