Skip to content

Commit eaf01a5

Browse files
committed
add codereview suggestions
1 parent 9482c63 commit eaf01a5

File tree

8 files changed

+707
-212
lines changed

8 files changed

+707
-212
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const PAGES = [
5151
],
5252
"Manipulating States and Operators" => "users_guide/states_and_operators.md",
5353
"Tensor Products and Partial Traces" => "users_guide/tensor.md",
54+
"Bloch Sphere Rendering" => "users_guide/plotting_the_bloch_sphere.md",
5455
"Time Evolution and Dynamics" => [
5556
"Introduction" => "users_guide/time_evolution/intro.md",
5657
"Time Evolution Solutions" => "users_guide/time_evolution/solution.md",

docs/src/users_guide/extensions/cairomakie.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ The supported plotting functions are listed as follows:
1919
| **Plotting Function** | **Description** |
2020
|:----------------------|:----------------|
2121
| [`plot_wigner`](@ref) | [Wigner quasipropability distribution](https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution) |
22-
| [`plot_fock_distribution`](@ref) | [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution |
22+
| [`plot_fock_distribution`](@ref) | [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution |
23+
| [`plot_bloch`](@ref) | [Qutip's Plotting on the Bloch Sphere](https://qutip.readthedocs.io/en/stable/guide/guide-bloch.html) |
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# [Plotting on the Bloch Sphere](@id doc: plotting_the_bloch_sphere.md)
2+
3+
```@setup Bloch_sphere_rendering
4+
using QuantumToolbox
5+
6+
using Makie
7+
using CairoMakie
8+
CairoMakie.enable_only_mime!(MIME"image/svg+xml"())
9+
```
10+
11+
## [Introduction](@id doc:Bloch_sphere_rendering)
12+
13+
When studying the dynamics of a two-level system, it's often convenient to visualize the state of the system by plotting the state vector or density matrix on the Bloch sphere.
14+
15+
In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), this can be done using the [`Bloch`](@ref) or [`plot_bloch`](@ref) methods that provide same syntax as [QuTiP](https://github.com/qutip/qutip).
16+
17+
## Create a Bloch Sphere
18+
19+
```@example Bloch_sphere_rendering
20+
b = Bloch();
21+
fig, _ = render(b)
22+
```
23+
24+
## Add a Single Data Point
25+
26+
```@example Bloch_sphere_rendering
27+
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
28+
add_points!(b, pnt)
29+
fig, _ = render(b)
30+
fig
31+
```
32+
33+
## Add a Single Vector
34+
35+
```@example Bloch_sphere_rendering
36+
clear!(b)
37+
vec = [0, 1, 0];
38+
add_vectors!(b, vec)
39+
fig, _ = render(b)
40+
fig
41+
```
42+
43+
## Add Multiple Vectors
44+
45+
```@example Bloch_sphere_rendering
46+
clear!(b)
47+
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
48+
add_vectors!(b, vecs)
49+
fig, _ = render(b)
50+
fig
51+
```
52+
53+
# Add Arc, Line, and Vector
54+
55+
```@example Bloch_sphere_rendering
56+
clear!(b)
57+
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
58+
add_vectors!(b, vec);
59+
add_line!(b, [1,0,0], [0,1,0])
60+
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
61+
fig, _ = render(b)
62+
fig
63+
```
64+
65+
# Add Quantum States
66+
67+
```@example Bloch_sphere_rendering
68+
clear!(b)
69+
x = basis(2, 0) + basis(2, 1)
70+
y = basis(2, 0) - im * basis(2, 1)
71+
z = basis(2, 0)
72+
b = Bloch()
73+
add_states!(b, [x, y, z])
74+
fig, _ = render(b)
75+
fig
76+
```
77+
78+
## Add Multiple Points Around the Equator
79+
80+
```@example Bloch_sphere_rendering
81+
th = range(0, 2π; length=20);
82+
clear!(b)
83+
xp = cos.(th);
84+
yp = sin.(th);
85+
zp = zeros(20);
86+
pnts = [xp, yp, zp] ;
87+
pnts = Matrix(hcat(xp, yp, zp)');
88+
add_points!(b, pnts);
89+
fig, ax = render(b);
90+
fig
91+
```
92+
93+
## Add Another Set of Points
94+
95+
```@example Bloch_sphere_rendering
96+
xz = zeros(20);
97+
yz = sin.(th);
98+
zz = cos.(th);
99+
points = hcat(xz, yz, zz)';
100+
add_points!(b, Matrix(points), meth=:s, color="orange");
101+
fig, ax = render(b);
102+
fig
103+
```

0 commit comments

Comments
 (0)