1
$\begingroup$

I have the really odd problem when it comes to plotting Bloch spheres using QuTip. Plotting state vectors works perfectly fine e.g.

from qutip import *
import numpy as np
import matplotlib.pyplot as plt

b = Bloch()
s = Qobj([[1],[0]])
b.add_states(s)
b.show()    

But when I try to plot points on the Bloch sphere using QuTiP

from qutip import *
import numpy as np
import matplotlib.pyplot as plt

b = Bloch()
pnt = [1,1,1]
b.add_points(pnt)
b.show()

I get the following error message

Traceback (most recent call last):
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_macosx.py", line 80, in _draw
    self.figure.draw(renderer)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 292, in draw
    reverse=True)):
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 291, in <lambda>
    key=lambda col: col.do_3d_projection(renderer),
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 545, in do_3d_projection
    ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 847, in _zalpha
    rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
  File "<__array_function__ internals>", line 6, in broadcast_to
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/Users/turbotanten/anaconda3/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 127, in _broadcast_to
    op_flags=['readonly'], itershape=shape, order='C')
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (0,4) and requested shape (2,4)

I have tried using different matplotlib backends like TkAgg without any success. I don't know how to fix this problem.

$\endgroup$
1
$\begingroup$

I found a solution to my problem here https://github.com/qutip/qutip/issues/1027

Apparently plotting points on the Bloch sphere does not work with Matplotlib v3.1.0. So I had to downgrade to v.3.0.3 for it to work!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.