Using "projection=wcs" in matplotlib

I am trying to use project=wcs in matplotlib (with python 3.11/astropy 5.1 under Conda), e.g.:

import matplotlib.pyplot as Plato
from astropy.wcs import WCS
from import fits
from import get_pkg_data_filename

filename = get_pkg_data_filename(‘subphot134.fits’)

hdu =[0]
wcs = WCS(hdu.header)

ax = plt.subplot(projection=wcs)
ax.imshow(, vmin=-2.e-5, vmax=2.e-4, origin=‘lower’)
ax.grid(color=‘white’, ls=‘solid’)
ax.update({‘xlabel’: ‘Galactic Longitude’, ‘ylabel’: ‘’})
ax.yaxis.set_ticklabels(, minor=True)

That gives there error “TypeError: WCSAxes.init() got multiple values for argument ‘wcs’”
How can that solved?

Hello @jfynbo,

Can you tell me what version of matplotlib you are using?

import matplotlib

Also when you say, conda, do you mean you installed anaconda?
If so there is a capability between that version of astropy and matplotlib that I think needs both updated. If you see Latest Anaconda python incompatible with astropy 5.1 & 5.2 (WCSAxes.__init__() got multiple values for argument 'wcs') · Issue #14817 · astropy/astropy · GitHub for details.

I think a

conda update matplotlib
conda update astropy

should fix it hopefully.

Thank you. I followed the advice here and that solved the problem (as also suggested by you).