Skip to content

Commit f64f1d6

Browse files
committed
change Bloch sphere rendering from Axis3 to Scene
1 parent 64ec15d commit f64f1d6

File tree

4 files changed

+136
-159
lines changed

4 files changed

+136
-159
lines changed

docs/src/users_guide/plotting_the_bloch_sphere.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ b = Bloch()
2424
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:
2525

2626
```@example Bloch_sphere_rendering
27-
fig, _ = render(b)
28-
fig
27+
scene = render(b)
28+
scene
2929
```
3030

3131
See the [API documentation for Bloch sphere](@ref doc-API:Bloch-Sphere) for a full list of other available functions.
@@ -37,8 +37,8 @@ As an example, we can add a single data point via [`add_points!`](@ref):
3737
```@example Bloch_sphere_rendering
3838
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
3939
add_points!(b, pnt)
40-
fig, _ = render(b)
41-
fig
40+
scene = render(b)
41+
scene
4242
```
4343

4444
## Add a single vector
@@ -48,8 +48,8 @@ Add a single vector via [`add_vectors!`](@ref):
4848
```@example Bloch_sphere_rendering
4949
vec = [0, 1, 0]
5050
add_vectors!(b, vec)
51-
fig, _ = render(b)
52-
fig
51+
scene = render(b)
52+
scene
5353
```
5454

5555
## Add a single quantum state
@@ -59,8 +59,8 @@ Add another vector corresponding to the ``|0\rangle`` state:
5959
```@example Bloch_sphere_rendering
6060
z0 = basis(2, 0)
6161
add_states!(b, z0)
62-
fig, _ = render(b)
63-
fig
62+
scene = render(b)
63+
scene
6464
```
6565

6666
## Add multiple data
@@ -69,8 +69,8 @@ We can also plot multiple points, vectors, and states at the same time by passin
6969

7070
```@example Bloch_sphere_rendering
7171
clear!(b)
72-
fig, _ = render(b)
73-
fig
72+
scene = render(b)
73+
scene
7474
```
7575

7676
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:
@@ -80,8 +80,8 @@ x = basis(2, 0) + basis(2, 1)
8080
y = basis(2, 0) + im * basis(2, 1)
8181
z = basis(2, 0)
8282
add_states!(b, [x, y, z])
83-
fig, _ = render(b)
84-
fig
83+
scene = render(b)
84+
scene
8585
```
8686

8787
!!! note "State normalization"
@@ -93,8 +93,8 @@ A similar method works for adding vectors:
9393
clear!(b)
9494
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
9595
add_vectors!(b, vecs)
96-
fig, _ = render(b)
97-
fig
96+
scene = render(b)
97+
scene
9898
```
9999

100100
# Add lines and arcs
@@ -104,8 +104,8 @@ You can also add lines and arcs via [`add_line!`](@ref) and [`add_arc!`](@ref) r
104104
```@example Bloch_sphere_rendering
105105
add_line!(b, x, y)
106106
add_arc!(b, y, z)
107-
fig, _ = render(b)
108-
fig
107+
scene = render(b)
108+
scene
109109
```
110110

111111
## Add multiple points
@@ -121,8 +121,8 @@ yp = sin.(th)
121121
zp = zeros(20)
122122
pnts = [xp, yp, zp]
123123
add_points!(b, pnts)
124-
fig, ax = render(b)
125-
fig
124+
scene = render(b)
125+
scene
126126
```
127127

128128
Notice that, in contrast to states or vectors, each point remains the same color as the initial point. This is because adding multiple data points using [`add_points!`](@ref) is interpreted, by default, to correspond to a single data point (single qubit state) plotted at different times. This is very useful when visualizing the dynamics of a qubit. If we want to plot additional qubit states we can call additional [`add_points!`](@ref) function:
@@ -132,8 +132,8 @@ xz = zeros(20)
132132
yz = sin.(th)
133133
zz = cos.(th)
134134
add_points!(b, [xz, yz, zz])
135-
fig, ax = render(b)
136-
fig
135+
scene = render(b)
136+
scene
137137
```
138138

139139
The color and shape of the data points is varied automatically by [`Bloch`](@ref). Notice how the color and point markers change for each set of data. Again, we have had to call [`add_points!`](@ref) twice because adding more than one set of multiple data points is not supported by the [`add_points!`](@ref) function.
@@ -148,17 +148,17 @@ yp = sin.(th)
148148
zp = zeros(20)
149149
pnts = [xp, yp, zp]
150150
add_points!(b, pnts, meth=:m) # add `meth=:m` to signify 'multi' colored points
151-
fig, ax = render(b)
152-
fig
151+
scene = render(b)
152+
scene
153153
```
154154

155155
Now, the data points cycle through a variety of predefined colors. Now lets add another set of points, but this time we want the set to be a single color, representing say a qubit going from the ``|0\rangle`` state to the ``|1\rangle`` state in the `y-z` plane:
156156

157157
```@example Bloch_sphere_rendering
158158
pnts = [xz, yz, zz]
159159
add_points!(b, pnts) # no `meth=:m`
160-
fig, ax = render(b)
161-
fig
160+
scene = render(b)
161+
scene
162162
```
163163

164164
## [Configuring the Bloch sphere](@id doc:Configuring-the-Bloch-sphere)
@@ -172,7 +172,7 @@ At the end of the last section we saw that the colors and marker shapes of the d
172172
| `b.lines` | Lines to draw on the sphere (points, style, properties) | `Vector{Tuple{Vector{Vector{Float64}},String}}()` (empty) |
173173
| `b.arcs` | Arcs to draw on the sphere | `Vector{Vector{Vector{Float64}}}()` (empty) |
174174
| `b.font_color` | Color of axis labels and text | `"black"` |
175-
| `b.font_size` | Font size for labels | `15` |
175+
| `b.font_size` | Font size for labels | `20` |
176176
| `b.frame_alpha` | Transparency of the frame background | `0.1` |
177177
| `b.frame_color` | Background color of the frame | `"gray"` |
178178
| `b.frame_limit` | Axis limits for the 3D frame (symmetric around origin) | `1.2` |

0 commit comments

Comments
 (0)