tight_layout() doesn't work properly on plots with a WCSAxes projection
See original GitHub issueA Matpltolib Axes
created with projection=wcs
does not play well with Matplotlib’s tight_layout()
method, that is supposed to re-size elements of a figure such that there are no overlapping labels/axes etc.
Consdier the following example:
import matplotlib.pyplot as plt
from astropy.wcs import WCS
from astropy.io import fits
from astropy.utils.data import get_pkg_data_filename
filename = get_pkg_data_filename('galactic_center/gc_msx_e.fits')
hdu = fits.open(filename)[0]
wcs = WCS(hdu.header)
fig = plt.figure(figsize=(8, 6))
n = 2
for i in range(n):
projection = wcs
# projection = None
plt.subplot(n, 1, i + 1, projection=projection)
# plt.imshow(hdu.data, vmin=-2.e-5, vmax=2.e-4, origin='lower')
plt.grid(color='white', ls='solid')
plt.xlabel('Galactic Longitude')
plt.ylabel('Galactic Latitude')
plt.title('WCSAxes plot')
fig.tight_layout()
plt.show()
projection=None
, no tight_layout:
projection=None
, with tight_layout:
(note how this re-organises things nicely)
projection='wcs'
, no tight_layout:
projection='wcs'
, with tight_layout:
Note how things actually get worse!
- astropy 3.1.2
- Matplotlib 3.0.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
python Matplotlib tight_layout() never work well - Stack Overflow
Summary: I want to use Matplotlib.tight_layout() to automatically optimize the layout of figures that contains any ...
Read more >Making plots with world coordinates (WCSAxes) — Astropy v5.2
Making plots with world coordinates (WCSAxes)¶. WCSAxes is a framework for making plots of Astronomical data in Matplotlib. It was previously distributed as ......
Read more >Tutorial maputils module — Kapteyn Package 2.3b6 ...
FITSimage.set_imageaxes() Then a helper function to get the right input is available. It is called maputils.prompt_imageaxes() which works ...
Read more >Tutorial maputils module — Kapteyn 3.0.0-beta documentation
FITSimage.set_imageaxes() Then a helper function to get the right input is ... is always plotted as a straight line, whatever the projection (so...
Read more >From sky coordinates to pixels (and back) - Joseph Long
She had some Herschel data in a FITS image with world coordinate system information (WCS) as well as some derived data in pixel...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For reference, some simpler code to reproduce this:
As I slowly descend into madness trying to work this out, a note that the end goal to get this working is to have
TickLabels
andAxisLabels
have their ownget_tight_bbox()
methods that can calculate their own Bboxes. This is going to need a lot of refactoring, but I suspect in the long run it should significantly tidy up the WCSAxes code.