# Using "projection=wcs" in matplotlib

**URL:** <https://community.openastronomy.org/t/using-projection-wcs-in-matplotlib/694>\
**Category:** Astropy\
**Created:** [June 23, 2023, 12:01pm UTC](https://community.openastronomy.org/t/using-projection-wcs-in-matplotlib/694 "2023-06-23T12:01:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfynbo](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/jfynbo/32/659_2.png) [@jfynbo](https://community.openastronomy.org/u/jfynbo)\
**Post date:** [June 23, 2023, 12:01pm UTC](https://community.openastronomy.org/t/using-projection-wcs-in-matplotlib/694/1 "2023-06-23T12:01:43Z")

</div>

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 [astropy.io](http://astropy.io) import fits  
from astropy.utils.data import get\_pkg\_data\_filename

filename = get\_pkg\_data\_filename(‘subphot134.fits’)

hdu = fits.open(filename)[0]  
wcs = WCS(hdu.header)

ax = plt.subplot(projection=wcs)  
ax.imshow(hdu.data, 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)  
ax.yaxis.set\_major\_locator(plt.NullLocator())  
plt.show()

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

---

<div class="post-metadata">

**Author:** ![nabobalis](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/nabobalis/32/14_2.png) [@nabobalis](https://community.openastronomy.org/u/nabobalis)\
**Post date:** [June 23, 2023, 5:22pm UTC](https://community.openastronomy.org/t/using-projection-wcs-in-matplotlib/694/2 "2023-06-23T17:22:50Z")

</div>

Hello @jfynbo,

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

```python
import matplotlib
print(matplotlib. __version__ )

```

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](https://github.com/astropy/astropy/issues/14817) for details.

I think a

```auto
conda update matplotlib
conda update astropy

```

should fix it hopefully.

---

<div class="post-metadata">

**Author:** ![jfynbo](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/jfynbo/32/659_2.png) [@jfynbo](https://community.openastronomy.org/u/jfynbo)\
**Post date:** [June 23, 2023, 5:23pm UTC](https://community.openastronomy.org/t/using-projection-wcs-in-matplotlib/694/3 "2023-06-23T17:23:34Z")

</div>

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

> <https://github.com/astropy/astropy/issues/14817>
>
> \### Description
> 
> I was trying to use wcs on an image following the steps in 
> …https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html 
> with astropy v5.1 and anaconda/python v 3.10 but I got an error:
> \`\`\`
> WCSAxes.\_\_init\_\_() got multiple values for argument 'wcs'
> \`\`\`
> I tried updating astropy to the latest version (5.2) with 'conda update astropy' but this had catastrophic effects of disappearing ipython and jupyter-notebook as well as other "jupyter-" executables from my anaconda3/bin/ directory (I dont understand how this is possible, but I confirmed it twice now). numpy also got corrupted, requiring me to completely uninstall anaconda and re-install it (which revived the astropy 5.1 version, but the wcs issue persists). 
> 
> My older computer has python 3.7 and astropy 4.3 and the code works just fine (so I will not be updating on that machine for now) so the issue seems to be compatibility between the two. 
> 
> \### Expected behavior
> 
> The code outlined in https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html should work but instead the command
> \`\`\`python
> plt.subplot(projection=wcs)
> \`\`\`
> results in these errors:
> \`\`\`
> In \[3\]: plt.subplot(projection=wcs)
> ...: 
> \---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
> Cell In\[3\], line 1
> \----\> 1 plt.subplot(projection=wcs)
> 
> File ~/anaconda3/lib/python3.10/site-packages/matplotlib/pyplot.py:1311, in subplot(\*args, \*\*kwargs)
> 1308 break
> 1309 else:
> 1310 # we have exhausted the known Axes and none match, make a new one!
> \-\> 1311 ax = fig.add\_subplot(\*args, \*\*kwargs)
> 1313 fig.sca(ax)
> 1315 axes\_to\_delete = \[other for other in fig.axes
> 1316 if other != ax and ax.bbox.fully\_overlaps(other.bbox)\]
> 
> File ~/anaconda3/lib/python3.10/site-packages/matplotlib/figure.py:743, in FigureBase.add\_subplot(self, \*args, \*\*kwargs)
> 740 args = tuple(map(int, str(args\[0\])))
> 741 projection\_class, pkw = self.\_process\_projection\_requirements(
> 742 \*args, \*\*kwargs)
> \--\> 743 ax = projection\_class(self, \*args, \*\*pkw)
> 744 key = (projection\_class, pkw)
> 745 return self.\_add\_axes\_internal(ax, key)
> 
> TypeError: WCSAxes.\_\_init\_\_() got multiple values for argument 'wcs'
> \`\`\`
> 
> \### Versions
> 
> import platform; print(platform.platform())
> import sys; print("Python", sys.version)
> import astropy; print("astropy", astropy.\_\_version\_\_)
> import numpy; print("Numpy", numpy.\_\_version\_\_)
> import erfa; print("pyerfa", erfa.\_\_version\_\_)
> import scipy; print("Scipy", scipy.\_\_version\_\_)
> import matplotlib; print("Matplotlib", matplotlib.\_\_version\_\_)
