@@ -205,9 +205,12 @@ def plot_bloch_vector_evolution(
205
205
Whether to show the sphere (by calling :code:`b.make_sphere()`).
206
206
return_Bloch: bool, optional
207
207
Whether to return the :class:`qutip.bloch.Bloch` instance
208
- bloch_kwargs : dict, optional
208
+ cbar_kwargs : dict, optional
209
209
A dictionary with keyword arguments to be fed into the
210
- qutip.Bloch constructor (if *b* not given).
210
+ colorbar constructor (if ``add_cbar == True``).
211
+ **bloch_kwargs: optional
212
+ Keyword arguments to be fed into the qutip.Bloch constructor
213
+ (if *b* not given).
211
214
212
215
Returns
213
216
-------
@@ -240,6 +243,9 @@ def plot_bloch_vector_evolution(
240
243
if b .axes is None :
241
244
b .axes = b .fig .add_subplot (projection = '3d' , azim = view [0 ], elev = view [1 ])
242
245
246
+ if show :
247
+ b .make_sphere ()
248
+
243
249
if n_samples is None :
244
250
# At least 100, at most 5000 points, default 10 points per smallest
245
251
# time interval
@@ -248,31 +254,32 @@ def plot_bloch_vector_evolution(
248
254
times = np .linspace (pulse .t [0 ], pulse .tau , n_samples )
249
255
propagators = pulse .propagator_at_arb_t (times )
250
256
points = get_bloch_vector (get_states_from_prop (propagators , psi0 ))
251
-
257
+ # Qutip convention: -x at +y, +y at +x
258
+ copy = points .copy ()
259
+ points [0 ] = copy [1 ]
260
+ points [1 ] = - copy [0 ]
261
+
262
+ # Check the matplotlib version to see if we can draw a color gradient line. If not, draw sphere
263
+ # after adding the points using the Bloch method. If yes, we apparently need to draw the sphere
264
+ # before manually adding the line collection, otherwise there is some strange thing going on in
265
+ # notebooks and the lines are not rendered.
252
266
if version .parse (matplotlib .__version__ ) < version .parse ('3.3.0' ):
253
267
# Colored trajectory not available.
254
- b .add_points ( points , meth = 'l' )
268
+ b .axes . plot ( * points , color = 'b' , alpha = 0.75 )
255
269
else :
256
270
points = points .T .reshape (- 1 , 1 , 3 )
257
- # Qutip convention: -x at +y, +y at +x
258
- copy = points .copy ()
259
- points [:, :, 0 ] = copy [:, :, 1 ]
260
- points [:, :, 1 ] = - copy [:, :, 0 ]
261
271
segments = np .concatenate ([points [:- 1 ], points [1 :]], axis = 1 )
262
272
263
273
cmap = plt .get_cmap (cmap )
264
274
segment_colors = cmap (np .linspace (0 , 1 , n_samples - 1 ))
265
- lc = collections .LineCollection (segments [:, :, :2 ], colors = segment_colors )
275
+ lc = collections .LineCollection (segments [:, :, :2 ], colors = segment_colors , alpha = 0.75 )
266
276
b .axes .add_collection3d (lc , zdir = 'z' , zs = segments [:, :, 2 ])
267
277
268
278
if add_cbar :
269
279
default_cbar_kwargs = dict (shrink = 2 / 3 , pad = 0.05 , label = r'$t$ ($\tau$)' , ticks = [0 , 1 ])
270
280
cbar_kwargs = {** default_cbar_kwargs , ** (cbar_kwargs or {})}
271
281
b .fig .colorbar (cm .ScalarMappable (cmap = cmap ), ** cbar_kwargs )
272
282
273
- if show :
274
- b .make_sphere ()
275
-
276
283
if return_Bloch :
277
284
return b
278
285
0 commit comments