You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/users_guide/plotting_the_bloch_sphere.md
+55-21Lines changed: 55 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,56 +15,63 @@ In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), this can be done u
15
15
16
16
## Create a Bloch Sphere
17
17
18
+
In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), creating a [`Bloch`](@ref) sphere is accomplished by calling either:
19
+
18
20
```@example Bloch_sphere_rendering
19
21
b = Bloch();
20
-
fig, _ = render(b)
22
+
```
23
+
24
+
which will load an instance of [`Bloch`](@ref). Before getting into the details of these objects, we can simply plot the blank [`Bloch`](@ref) sphere associated with these instances via:
25
+
26
+
```@example Bloch_sphere_rendering
27
+
fig, _ = render(b);
28
+
fig
21
29
```
22
30
23
31
## Add a Single Data Point
24
32
33
+
As an example, we can add a single data point via [`add_points!`](@ref):
34
+
25
35
```@example Bloch_sphere_rendering
26
-
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
27
-
add_points!(b, pnt)
28
-
fig, _ = render(b)
36
+
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)];
37
+
add_points!(b, pnt);
38
+
fig, _ = render(b);
29
39
fig
30
40
```
31
41
32
42
## Add a Single Vector
33
43
44
+
and then a single vector via [`add_vectors!`](@ref):
45
+
34
46
```@example Bloch_sphere_rendering
35
-
clear!(b)
36
47
vec = [0, 1, 0];
37
48
add_vectors!(b, vec)
38
49
fig, _ = render(b)
39
50
fig
40
51
```
41
52
42
-
## Add Multiple Vectors
53
+
and then add another vector corresponding to the ``|0\rangle`` state:
43
54
44
55
```@example Bloch_sphere_rendering
45
-
clear!(b)
46
-
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
47
-
add_vectors!(b, vecs)
56
+
x = basis(2, 0)
57
+
add_states!(b, [x])
48
58
fig, _ = render(b)
49
59
fig
50
60
```
51
61
52
-
# Add Arc, Line, and Vector
62
+
## Add Multiple Vectors
63
+
64
+
We can also plot multiple points, vectors, and states at the same time by passing arrays instead of individual elements via [`add_vectors!](@ref). Before giving an example, we can use [`clear!`](@ref) to remove the current data from our [`Bloch`](@ref) sphere instead of creating a new instance:
53
65
54
66
```@example Bloch_sphere_rendering
55
67
clear!(b)
56
-
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
57
-
add_vectors!(b, vec);
58
-
add_line!(b, [1,0,0], [0,1,0])
59
-
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
60
68
fig, _ = render(b)
61
69
fig
62
70
```
63
71
64
-
# Add Quantum States
72
+
Now on the same [`Bloch`](@ref) sphere, we can plot the three states via [`add_states!`](@ref) associated with the `x`, `y`, and `z` directions:
65
73
66
74
```@example Bloch_sphere_rendering
67
-
clear!(b)
68
75
x = basis(2, 0) + basis(2, 1)
69
76
y = basis(2, 0) - im * basis(2, 1)
70
77
z = basis(2, 0)
@@ -74,29 +81,56 @@ fig, _ = render(b)
74
81
fig
75
82
```
76
83
77
-
## Add Multiple Points Around the Equator
84
+
a similar method works for adding vectors:
85
+
86
+
```@example Bloch_sphere_rendering
87
+
clear!(b)
88
+
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
89
+
add_vectors!(b, vecs)
90
+
fig, _ = render(b)
91
+
fig
92
+
```
93
+
94
+
# Add Arc, Line, and Vector
95
+
96
+
You can also add lines and arcs via [`add_line!`](@ref) and [`add_arc!`](@ref) respectively:
97
+
98
+
```@example Bloch_sphere_rendering
99
+
clear!(b)
100
+
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
101
+
add_vectors!(b, vec);
102
+
add_line!(b, [1,0,0], [0,1,0])
103
+
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
104
+
fig, _ = render(b)
105
+
fig
106
+
```
107
+
108
+
## Add Multiple Points
109
+
110
+
Adding multiple points to the [`Bloch`](@ref) sphere works slightly differently than adding multiple states or vectors. For example, lets add a set of `20` points around the equator (after calling [`clear!`](@ref)):
78
111
79
112
```@example Bloch_sphere_rendering
80
113
th = range(0, 2π; length=20);
81
114
clear!(b)
82
115
xp = cos.(th);
83
116
yp = sin.(th);
84
117
zp = zeros(20);
85
-
pnts = [xp, yp, zp] ;
86
-
pnts = Matrix(hcat(xp, yp, zp)');
118
+
pnts = [xp, yp, zp];
87
119
add_points!(b, pnts);
88
120
fig, ax = render(b);
89
121
fig
90
122
```
91
123
92
124
## Add Another Set of Points
93
125
126
+
If we want to plot additional qubit states we can call additional [`add_points!`](@ref) functions:
0 commit comments