# Bloch sphere in TikZ, explained line by line

> How the Bloch sphere is drawn in plain TikZ: a circle, a dashed ellipse, three axes, a projected vector and angle pics, plus two 3D variations.

URL: https://www.labcanvas.com/tikz/examples/physics/bloch-sphere

Updated 2026-11-22. Original figure: Bloch sphere, © Janosh Riebesell and contributors, MIT licence (licence text: https://www.labcanvas.com/tikz-library/credits.html#janosh), from https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/bloch-sphere/bloch-sphere.tex. Walkthrough and variations by LabCanvas; the variation code is CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/). Pictures typeset with TeX Live 2026 and PGF 3.1.12. Category: [TikZ physics examples](https://www.labcanvas.com/tikz/examples/physics).

## Quick answer

This figure is a Bloch sphere drawn in plain TikZ: a circle for the sphere, a dashed ellipse for the equator, three axes x 1, x 2, x 3, a vector a with its dashed projection onto the equatorial plane, and the angles θ and φ. It is a flat sketch with hand-picked 2D coordinates rather than a true 3D projection, which keeps it to about twenty lines. The angles are `angle` pics from the `angles` library, labelled with the `quotes` syntax; the variations show how to place the vector from θ and φ with a real 3D view.

## The figure and its code

![Bloch sphere: a large circle with a dashed horizontal ellipse for the equator, axes x3 up, x2 right and x1 down to the left from the centre, a vector a from the centre to a dot labelled a, its dashed projection onto the equator, a grey arc marked theta between x3 and a, and a grey arc marked phi between x1 and the projection.](https://www.labcanvas.com/tikz-snippets/fig-bloch-sphere/original.webp)

Copyright (c) 2021 Janosh Riebesell, MIT licence (https://www.labcanvas.com/tikz-library/credits.html#janosh). The code below is exactly the library's file (pdfLaTeX); its first lines name the source and the licence, and the MIT licence asks that they stay with the code. Open it in the TikZ editor from the page: https://www.labcanvas.com/tikz/examples/physics/bloch-sphere

```latex
% Bloch sphere
% Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/bloch-sphere/bloch-sphere.tex
% Copyright (c) 2021 Janosh Riebesell. MIT licence: https://github.com/janosh/diagrams/blob/main/license
% The licence’s copyright and permission notice: https://www.labcanvas.com/tikz-library/credits.html
\documentclass[tikz]{standalone}

\usetikzlibrary{angles,quotes}

\begin{document}
\begin{tikzpicture}

  % Define radius
  \def\r{3}

  % Bloch vector
  \draw (0, 0) node[circle, fill, inner sep=1] (orig) {} -- (\r/3, \r/2) node[circle, fill, inner sep=0.7, label=above:$\vec{a}$] (a) {};
  \draw[dashed] (orig) -- (\r/3, -\r/5) node (phi) {} -- (a);

  % Sphere
  \draw (orig) circle (\r);
  \draw[dashed] (orig) ellipse (\r{} and \r/3);

  % Axes
  \draw[->] (orig) -- ++(-\r/5, -\r/3) node[below] (x1) {$x_1$};
  \draw[->] (orig) -- ++(\r, 0) node[right] (x2) {$x_2$};
  \draw[->] (orig) -- ++(0, \r) node[above] (x3) {$x_3$};

  % Angles
  \pic [draw=gray, text=gray, ->, "$\phi$"] {angle = x1--orig--phi};
  \pic [draw=gray, text=gray, <-, "$\theta$", angle eccentricity=1.4] {angle = a--orig--x3};

\end{tikzpicture}
\end{document}
```

## The document and the radius

*Lines 5–13 of the code.*

`\documentclass[tikz]{standalone}` loads TikZ and crops the page to the picture. Two libraries are needed: `angles` for the angle pics and `quotes` for writing their labels as `"$\phi$"`. `\def\r{3}` stores the sphere’s radius in a macro so that every coordinate can be written as a fraction of it. Beware that `\r` is also LaTeX’s ring accent (as in å); redefining it inside the picture is harmless here, but a name such as `\R` or `\radius` avoids the clash.

## The vector and its projection

*Lines 15–17 of the code.*

Line 16 draws the vector a and places two nodes on the same path: `node[circle, fill, inner sep=1] (orig) {}` at the start, a small filled dot named `orig`, and another at the end, at `(\r/3, \r/2)`, = (1, 1.5), with `label=above:$\vec{a}$`. A node with empty text and `inner sep=1` (1pt, since a length without unit is read in points) is simply a dot of that size.

Line 17 is the dashed projection: from the origin to `(\r/3, -\r/5)`, the foot of the vector on the equatorial plane, then up to a. The empty node named `phi` marks the foot so that the φ angle can refer to it. The foot lies directly below a (the same x, 1), which is what makes the dashed line vertical.

## The sphere and the equator

*Lines 19–21 of the code.*

`\draw (orig) circle (\r);` is the outline, and `\draw[dashed] (orig) ellipse (\r{} and \r/3);` the equator, a flattened circle as wide as the sphere and a third as tall. Both use the older syntax with the radius in parentheses (the newer one is `circle[radius=\r]` and `ellipse[x radius=\r, y radius=\r/3]`). The empty group in `\r{} and` matters: TeX swallows the space after a command name, so without `{}` TikZ would see “3and” and miss the keyword `and`. The whole ellipse is dashed, front and back; a 3D drawing would show the front half solid, as in the first variation.

## Three axes in an oblique view

*Lines 23–26 of the code.*

Each axis is a relative line from the origin, `-- ++(\r, 0)` for x 2 and `-- ++(0, \r)` for x 3, ending in a label node named after the axis. x 1, the axis towards the viewer, is faked with a short line down and to the left, `++(-\r/5, -\r/3)`: the oblique direction suggests depth without any 3D maths. That is also why the picture is a sketch: the vector a and the ellipse are not computed from a common viewpoint, they are just drawn to look right.

## The angles as pics

*Lines 28–30 of the code.*

`\pic [draw=gray, text=gray, ->, "$\phi$"] {angle = x1--orig--phi};` draws the angle at `orig` between the lines towards `x1` and towards `phi`: an arc of the default `angle radius` (5 mm) with an arrow tip at its end, on the side of the projection. The quotes syntax sets the label, which sits at `angle eccentricity` times the radius from the vertex (0.6 by default, inside the arc).

The θ angle, `angle = a--orig--x3`, uses `<-`, so the tip is at the start of the arc, on the side of a: the arrow runs from the x 3 axis to the vector, the direction in which θ is measured. `angle eccentricity=1.4` moves its label outside the narrow arc. One subtlety: `x1` is the label node below the tip of the axis, not the tip itself, so the φ arc starts a few degrees off the axis line; at 5 mm that is invisible, but a `\coordinate` at the tip would be exact.

## Techniques used

- [Angle pics with labels](https://www.labcanvas.com/tikz/circles-arcs): `\pic {angle = x1--orig--phi}` with `"$\phi$"`, `angle radius` and `angle eccentricity`.
- [Circles and ellipses](https://www.labcanvas.com/tikz/circles-arcs): the sphere outline and the dashed equator, in the older parenthesis syntax.
- [Relative coordinates](https://www.labcanvas.com/tikz/coordinates): `++(\r, 0)` draws each axis from the origin.
- [Bloch sphere drawings](https://www.labcanvas.com/tikz/bloch-sphere): conventions for qubit states, poles and angles on the Bloch sphere.
- [Physics diagrams](https://www.labcanvas.com/tikz/physics-diagrams): vectors, projections and angle marks in physics figures.

## Variations

Our own code, CC0 1.0, each typeset with TeX Live 2026 in a standalone document with the preamble lines shown.

### A qubit state placed from θ and φ in a true 3D view

TikZ can project 3D coordinates if you give it the screen directions of the three unit vectors. With `x={(-0.5cm,-0.296cm)}, y={(0.866cm,-0.171cm)}, z={(0cm,0.94cm)}` (an orthographic view from 30° azimuth and 20° elevation), a point is written as `(x,y,z)` and the state goes exactly where its angles say: `({\R*sin(\th)*cos(\ph)}, {\R*sin(\th)*sin(\ph)}, {\R*cos(\th)})`. The equator is a `plot` of a circle in the xy-plane, solid in front and dashed behind, and the θ and φ arcs are short plots in their own planes. Change `\th` and `\ph` and everything follows.

![A light blue Bloch sphere in perspective with axes x, y and z, the poles marked |0⟩ at the top and |1⟩ at the bottom, the equator solid in front and dashed behind, a red vector |ψ⟩ with its dashed projection onto the equator, blue arcs marking theta from the z axis and phi from the x axis, and the formula |ψ⟩ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩.](https://www.labcanvas.com/tikz-snippets/fig-bloch-sphere/qubit-state.webp)

*a qubit state |ψ⟩ at θ = 50°, φ = 60° on a Bloch sphere drawn with 3D coordinates*

Preamble: `\usepackage{tikz}`

```latex
\begin{tikzpicture}[
    % an orthographic view: azimuth 30 degrees, elevation 20 degrees
    x={(-0.5cm,-0.296cm)}, y={(0.866cm,-0.171cm)}, z={(0cm,0.94cm)},
    >=stealth, line cap=round,
  ]
  \def\R{2.6}   % radius
  \def\th{50}   % polar angle theta of the state
  \def\ph{60}   % azimuth phi of the state
  % the sphere's outline, and the equator: front half solid, back half dashed
  \fill[blue!6] (0,0,0) circle[radius=\R cm];
  \draw (0,0,0) circle[radius=\R cm];
  \draw[gray, dashed] plot[domain=120:300, samples=60, smooth, variable=\t] ({\R*cos(\t)}, {\R*sin(\t)}, 0);
  \draw[gray] plot[domain=-60:120, samples=60, smooth, variable=\t] ({\R*cos(\t)}, {\R*sin(\t)}, 0);
  % axes and poles
  \draw[->] (0,0,0) -- (1.35*\R,0,0) node[below left] {$x$};
  \draw[->] (0,0,0) -- (0,1.3*\R,0) node[right] {$y$};
  \draw[->] (0,0,0) -- (0,0,1.25*\R) node[above] {$z$};
  \fill (0,0,\R) circle[radius=1.3pt] node[above right] {$|0\rangle$};
  \fill (0,0,-\R) circle[radius=1.3pt] node[below right] {$|1\rangle$};
  % the state from its two angles, and its projection on the equator
  \coordinate (psi) at ({\R*sin(\th)*cos(\ph)}, {\R*sin(\th)*sin(\ph)}, {\R*cos(\th)});
  \coordinate (proj) at ({\R*sin(\th)*cos(\ph)}, {\R*sin(\th)*sin(\ph)}, 0);
  \draw[dashed] (0,0,0) -- (proj) -- (psi);
  \draw[->, very thick, red!70!black] (0,0,0) -- (psi) node[above right] {$|\psi\rangle$};
  % the angles as short arcs in 3D
  \draw[->, blue!70!black] plot[domain=0:\ph, samples=20, smooth, variable=\t] ({0.7*cos(\t)}, {0.7*sin(\t)}, 0);
  \node[blue!70!black] at ({1.05*cos(\ph/2)}, {1.05*sin(\ph/2)}, 0) {$\varphi$};
  \draw[->, blue!70!black] plot[domain=0:\th, samples=20, smooth, variable=\t]
    ({0.9*sin(\t)*cos(\ph)}, {0.9*sin(\t)*sin(\ph)}, {0.9*cos(\t)});
  \node[blue!70!black] at ({1.25*sin(\th/2)*cos(\ph)}, {1.25*sin(\th/2)*sin(\ph)}, {1.25*cos(\th/2)}) {$\theta$};
  \node[anchor=west] at (0, 1.05*\R, -0.9*\R)
    {$|\psi\rangle = \cos\frac{\theta}{2}|0\rangle + e^{i\varphi}\sin\frac{\theta}{2}|1\rangle$};
\end{tikzpicture}
```

### The six cardinal states from one \foreach

The same view with the six states on the axes, |0⟩ and |1⟩ at the poles and |±⟩ and |±i⟩ on the equator. Each state is one entry of a `\foreach` list with five fields, θ, φ, label, label position and line style, so the vectors on the far side of the sphere can be dashed. The sphere is `ball color` shading made lighter with `opacity=0.4`.

![A softly shaded sphere with six red arrows from the centre: |0⟩ up, |1⟩ down (dashed), |+⟩ towards the viewer at lower left, |−⟩ away from the viewer (dashed), |+i⟩ to the right and |−i⟩ to the left (dashed), over a solid front and dashed back equator.](https://www.labcanvas.com/tikz-snippets/fig-bloch-sphere/cardinal-states.webp)

*the six cardinal qubit states drawn from a list of angles; states behind the sphere are dashed*

Preamble: `\usepackage{tikz}`

```latex
\begin{tikzpicture}[
    x={(-0.5cm,-0.296cm)}, y={(0.866cm,-0.171cm)}, z={(0cm,0.94cm)},
    >=stealth, font=\small,
  ]
  \def\R{2.2}
  \shade[ball color=blue!25, opacity=0.4] (0,0,0) circle[radius=\R cm];
  \draw (0,0,0) circle[radius=\R cm];
  \draw[gray, dashed] plot[domain=120:300, samples=60, smooth, variable=\t] ({\R*cos(\t)}, {\R*sin(\t)}, 0);
  \draw[gray] plot[domain=-60:120, samples=60, smooth, variable=\t] ({\R*cos(\t)}, {\R*sin(\t)}, 0);
  % the six states on the axes: theta, phi, label, label position, line style
  % (states on the far side of the sphere are dashed)
  \foreach \th/\ph/\lab/\pos/\sty in {
      0/0/{|0\rangle}/above/solid, 180/0/{|1\rangle}/below/dashed,
      90/0/{|{+}\rangle}/below left/solid, 90/180/{|{-}\rangle}/above right/dashed,
      90/90/{|{+i}\rangle}/right/solid, 90/270/{|{-i}\rangle}/left/dashed} {
    \draw[->, thick, red!70!black, \sty]
      (0,0,0) -- ({\R*sin(\th)*cos(\ph)}, {\R*sin(\th)*sin(\ph)}, {\R*cos(\th)}) node[\pos] {$\lab$};
  }
\end{tikzpicture}
```

## Frequently asked questions

### How do I draw a Bloch sphere in TikZ?

Draw a circle for the sphere, an ellipse for the equator (dashed behind), three axes from the centre and the state vector, then mark θ and φ with \pic {angle=…} from the angles library. For a vector placed exactly from θ and φ, set the x, y and z unit vectors of the picture and use 3D coordinates, as in the first variation.

### How do I draw an angle with an arrow and a label in TikZ?

Load \usetikzlibrary{angles, quotes} and write \pic [draw, ->, "$\theta$", angle radius=6mm] {angle = A--O--B}; where A, O and B are named coordinates or nodes. angle eccentricity moves the label towards or away from the vertex.

### Why does ellipse (\r{} and \r/3) need the {}?

TeX drops the space after a command name, so \r and would reach TikZ as 3and and the keyword and would not be found. The empty group {} ends the command name and keeps the space.

## References

- [janosh/diagrams at commit 7a79b31: assets/bloch-sphere/bloch-sphere.tex (MIT licence)](https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/bloch-sphere/bloch-sphere.tex)
- [PGF/TikZ manual, §13.2.1 Canvas, XYZ, and Polar Coordinate Systems](https://tikz.dev/tikz-coordinates#sec-13.2.1)
- [PGF/TikZ manual, §13.4.1 Specifying Relative Coordinates (++)](https://tikz.dev/tikz-coordinates#sec-13.4.1)
- [PGF/TikZ manual, §14.6 The Circle and Ellipse Operations](https://tikz.dev/tikz-paths#sec-14.6)
- [PGF/TikZ manual, §14.12 The Plot Operation](https://tikz.dev/tikz-paths#sec-14.12)
- [PGF/TikZ manual, §15.7 Shading a Path (ball color)](https://tikz.dev/tikz-actions#sec-15.7)
- [PGF/TikZ manual, §17.10.2 The Label Option](https://tikz.dev/tikz-shapes#sec-17.10.2)
- [PGF/TikZ manual, §41 Angle Library](https://tikz.dev/library-angle)
- [PGF/TikZ manual, §17.10.4 The Quotes Syntax](https://tikz.dev/tikz-shapes#sec-17.10.4)

## TikZ guides for these techniques

- [Bloch sphere in TikZ: drawing a qubit state in LaTeX](https://www.labcanvas.com/tikz/bloch-sphere): A Bloch sphere in LaTeX with TikZ: shaded sphere, dashed back equator, axes, the six basis states, a state with θ and φ, tikz-3dplot and blochsphere.
- [TikZ physics diagrams: forces, springs, optics, waves and fields](https://www.labcanvas.com/tikz/physics-diagrams): Physics diagrams in TikZ with code: free-body diagram, inclined plane, spring and pendulum, a lens ray diagram, waves, energy levels and a dipole field.
- [How to draw circles, ellipses and arcs in TikZ](https://www.labcanvas.com/tikz/circles-arcs): Draw circles, ellipses and arcs in TikZ: circle[radius], ellipse radii, arc start/end angle and centre, half circles, sectors, pie charts and angle marks.
- [TikZ coordinates, paths, \foreach, scopes and styles](https://www.labcanvas.com/tikz/coordinates): TikZ coordinates (polar, relative ++, named, calc, intersections), paths and controls, \foreach loops, scopes, \tikzset styles, decorations and grids.
- [Quantikz: quantum circuit diagrams in LaTeX](https://www.labcanvas.com/tikz/quantikz): Quantum circuits in LaTeX with quantikz 1.0.1: gates, CNOT, measurement, classical wires, slices, Bell state, teleportation, quantikz vs quantikz2.
