Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions docs/src/users_guide/plotting_the_bloch_sphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ b = Bloch()
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:

```@example Bloch_sphere_rendering
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -37,7 +38,8 @@ As an example, we can add a single data point via [`add_points!`](@ref):
```@example Bloch_sphere_rendering
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
add_points!(b, pnt)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -48,7 +50,8 @@ Add a single vector via [`add_vectors!`](@ref):
```@example Bloch_sphere_rendering
vec = [0, 1, 0]
add_vectors!(b, vec)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -59,7 +62,8 @@ Add another vector corresponding to the ``|0\rangle`` state:
```@example Bloch_sphere_rendering
z0 = basis(2, 0)
add_states!(b, z0)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -69,7 +73,8 @@ We can also plot multiple points, vectors, and states at the same time by passin

```@example Bloch_sphere_rendering
clear!(b)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -80,7 +85,8 @@ x = basis(2, 0) + basis(2, 1)
y = basis(2, 0) - im * basis(2, 1)
z = basis(2, 0)
add_states!(b, [x, y, z])
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -93,7 +99,8 @@ A similar method works for adding vectors:
clear!(b)
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
add_vectors!(b, vecs)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -104,7 +111,8 @@ You can also add lines and arcs via [`add_line!`](@ref) and [`add_arc!`](@ref) r
```@example Bloch_sphere_rendering
add_line!(b, x, y)
add_arc!(b, y, z)
fig, _ = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -121,7 +129,8 @@ yp = sin.(th)
zp = zeros(20)
pnts = [xp, yp, zp]
add_points!(b, pnts)
fig, ax = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -132,7 +141,8 @@ xz = zeros(20)
yz = sin.(th)
zz = cos.(th)
add_points!(b, [xz, yz, zz])
fig, ax = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -148,7 +158,8 @@ yp = sin.(th)
zp = zeros(20)
pnts = [xp, yp, zp]
add_points!(b, pnts, meth=:m) # add `meth=:m` to signify 'multi' colored points
fig, ax = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand All @@ -157,7 +168,8 @@ Now, the data points cycle through a variety of predefined colors. Now lets add
```@example Bloch_sphere_rendering
pnts = [xz, yz, zz]
add_points!(b, pnts) # no `meth=:m`
fig, ax = render(b)
fig = Figure(size = (700, 700), figure_padding = 0)
fig, ax = render(b,location = fig[1,1])
fig
```

Expand Down Expand Up @@ -200,4 +212,4 @@ These properties can also be accessed via the `print` command:
```@example Bloch_sphere_rendering
b = Bloch()
print(b)
```
```
2 changes: 1 addition & 1 deletion src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,4 @@ plot_bloch(
kwargs...,
) where {OpType<:Union{Ket,Bra,Operator}} = plot_bloch(makeVal(library), state; kwargs...)
plot_bloch(::Val{T}, state::QuantumObject{OpType}; kwargs...) where {T,OpType<:Union{Ket,Bra,Operator}} =
throw(ArgumentError("The specified plotting library $T is not available. Try running `using $T` first."))
throw(ArgumentError("The specified plotting library $T is not available. Try running `using $T` first."))