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
+60-1Lines changed: 60 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,4 +211,63 @@ These properties can also be accessed via the `print` command:
211
211
```@example Bloch_sphere_rendering
212
212
b = Bloch()
213
213
print(b)
214
-
```
214
+
```
215
+
216
+
## Animating with the Bloch sphere
217
+
218
+
The [`Bloch`](@ref) structure was designed from the outset to generate animations. To animate a set of vectors or data points, the basic idea is: plot the data at time ``t_1``, save the sphere, clear the sphere, plot data at ``t_2``, and so on. The easiest way to animate data on the Bloch sphere is to use the `record` function provided by [`Makie.jl`](https://docs.makie.org/stable/). We will demonstrate this functionality with the following example: the decay of a qubit on the Bloch sphere.
Here, we set the keyword argument `location = lscene` in the last `render` function to update the existing Bloch sphere without creating new `Figure` and `LScene`. This is efficient when drawing animations.
Copy file name to clipboardExpand all lines: ext/QuantumToolboxMakieExt.jl
+33-7Lines changed: 33 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -337,14 +337,24 @@ Render the Bloch sphere visualization from the given [`Bloch`](@ref) object `b`.
337
337
# Arguments
338
338
339
339
- `b::Bloch`: The Bloch sphere object containing states, vectors, and settings to visualize.
340
-
- `location::Union{GridPosition,Nothing}`: The location of the plot in the layout. If `nothing`, the plot is created in a new figure. Default is `nothing`.
340
+
- `location::Union{GridPosition,LScene,Nothing}`: The location of the plot in the layout or `Makie.LScene`
341
+
341
342
342
343
# Returns
343
344
344
345
- A tuple `(fig, lscene)` where `fig` is the figure object and `lscene` is the LScene object used for plotting. These can be further manipulated or saved by the user.
346
+
347
+
# Notes
348
+
349
+
The keyword argument `location` can be in the either type:
350
+
351
+
- `Nothing` (default): Create a new figure and plot the Bloch sphere.
352
+
- `GridPosition`: Plot the Bloch sphere in the specified location of the plot in the layout.
353
+
- `LScene`: Update the existing Bloch sphere using new data and settings in `b::Bloch` without creating new `Figure` and `LScene` (efficient for drawing animation).
345
354
"""
346
355
function QuantumToolbox.render(b::Bloch; location =nothing)
347
-
fig, lscene =_setup_bloch_plot!(b, location)
356
+
fig, lscene =_setup_bloch_plot!(location)
357
+
_setup_bloch_camara!(b, lscene)
348
358
_draw_bloch_sphere!(b, lscene)
349
359
_add_labels!(b, lscene)
350
360
@@ -358,30 +368,46 @@ function QuantumToolbox.render(b::Bloch; location = nothing)
0 commit comments