question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WCSAxes and shared axis

See original GitHub issue

I am trying to plot a figure with several WCSAxes where I would like to have the sharex/sharey feature working. The basic example would be:

import numpy as np
from matplotlib import pyplot as plt
from astropy.io.fits import ImageHDU
from astropy.wcs import WCS
plt.ion()

# Same physical region on the sky
HDUs = []
for index in range(3):
    npix = (index+1)*2+1
    this_map  = np.zeros((npix, npix))
    this_map[1,1] = 1

    w = WCS(naxis=2)
    w.wcs.crpix = [(npix+1)/2, (npix+1)/2]
    w.wcs.cdelt = [3./npix, 3./npix]
    HDUs.append(ImageHDU(this_map, w.to_header()))

# Proper figure without shared axis
fig = plt.figure()
for index, hdu in enumerate(HDUs):
    if index == 0:
        ax_ref = fig.add_subplot(len(HDUs), 1, index+1,
                                 projection=WCS(hdu.header))
        ax_ref.imshow(hdu.data)
    else:
        ax = fig.add_subplot(len(HDUs), 1, index+1,
                             projection=WCS(hdu.header))
        ax.imshow(hdu.data)

# Failing figure with shared axes
fig = plt.figure()
for index, hdu in enumerate(HDUs):
    if index == 0:
        ax_ref = fig.add_subplot(len(HDUs), 1, index+1,
                                 projection=WCS(hdu.header))
        ax_ref.imshow(hdu.data)
    else:
        ax = fig.add_subplot(len(HDUs), 1, index+1,
                             projection=WCS(hdu.header),
                             sharex=ax_ref, sharey=ax_ref)
        ax.imshow(hdu.data)

But unfortunately it seems that the sharex sharey keyword only applied on the pixel scale. Is there a way to make it work on world coordinates ?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dstansbycommented, Dec 2, 2022

No, it doesn’t. The axes are shared on a ‘pixel’ level, not a ‘world coordinate’ level. To fix this issue they would need to be shared on a ‘world coordinate’ level.

0reactions
pllimcommented, Dec 2, 2022

Would @dstansby 's code above resolve the original question? Can we close this issue? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

WCSAxes — Astropy v5.2
The main axes class that can be used to show world coordinates from a WCS. Parameters. fig Figure. The figure to add the...
Read more >
WCSAxes — Astropy v2.0.dev18967 - Read the Docs
The main axes class that can be used to show world coordinates from a WCS. Parameters: fig : Figure. The figure to ...
Read more >
Clearing a matplotlib axis labels, ticks and locators while ...
I wonder if anyone could please share any advice ... File "/anaconda3/lib/python3.8/site-packages/astropy/visualization/wcsaxes/core.py", ...
Read more >
Source code for sunpy.visualization.wcsaxes_compat
WCSAxes ` The current axes, or a new one if created. ... the native coordinates to be bottom and left only so they...
Read more >
Matplotlib — Visualization with Python
Join our community at discourse.matplotlib.org to get help, share your work, and discuss contributing & development. Check out the Matplotlib tag on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found