qutip / qutip

QuTiP: Quantum Toolbox in Python
https://qutip.org
BSD 3-Clause "New" or "Revised" License
1.69k stars 635 forks source link

Matplotlib update broke qpt_plot_combined #2233

Closed theodotk closed 11 months ago

theodotk commented 1 year ago

Bug Description

It seems that in new matplotlib version they separated classes Axes and Axes3d, so some plotting functions that have 3d aspects don't work as expected anymore. See example in the code below.

Code to Reproduce the Bug

from qutip import qpt_plot_combined
qpt_plot_combined(np.eye(4), [["I", "X", "Y", "Z"]])

Code Output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 2
      1 from qutip import qpt_plot_combined
----> 2 qpt_plot_combined(np.eye(4), [["I", "X", "Y", "Z"]])

File ~\AppData\Local\pypoetry\Cache\virtualenvs\photonic-component-simulator-biULA8HA-py3.9\lib\site-packages\qutip\tomography.py:143, in qpt_plot_combined(chi, lbls_list, title, fig, ax, figsize, threshold)
    140 if not title:
    141     title = r"$\chi$"
--> 143 matrix_histogram_complex(chi, xlabels, xlabels, title=title, ax=ax,
    144                          threshold=threshold)
    146 return fig, ax

File ~\AppData\Local\pypoetry\Cache\virtualenvs\photonic-component-simulator-biULA8HA-py3.9\lib\site-packages\qutip\visualization.py:820, in matrix_histogram_complex(M, xlabels, ylabels, title, limits, phase_limits, colorbar, fig, ax, threshold)
    818 # x axis
    819 xtics = -0.5 + np.arange(M.shape[0])
--> 820 ax.axes.w_xaxis.set_major_locator(plt.FixedLocator(xtics))
    821 if xlabels:
    822     nxlabels = len(xlabels)

AttributeError: 'Axes3D' object has no attribute 'w_xaxis'

Expected Behaviour

There should be a plot and not an error

Your Environment

QuTiP vesion: '4.7.3'
matplotlib version: '3.8.0'

Additional Context

No response

nleehone commented 1 year ago

This seems to be because of this change: https://matplotlib.org/3.8.0/api/prev_api_changes/api_changes_3.8.0.html#axes3d

The solution from the docs:

The w_xaxis, w_yaxis, and w_zaxis attributes are now removed. Instead use xaxis, yaxis, and zaxis.