Skip to content

Commit

Permalink
Merge pull request #1955 from larrybradley/griddedpsf-cbar
Browse files Browse the repository at this point in the history
Improved GriddedPSFModel plot_grid color bar
  • Loading branch information
larrybradley authored Nov 20, 2024
2 parents 5a04d71 + ba77a01 commit d73bfb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ API Changes
``GriddedPSFModel`` ``plot_grid`` method when ``deltas=True``.
[#1954]

- The ``GriddedPSFModel`` ``plot_grid`` color bar now matches the
height of the displayed image. [#1955]


2.0.2 (2024-10-24)
------------------
Expand Down
13 changes: 9 additions & 4 deletions photutils/psf/model_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def plot_grid(self, *, ax=None, vmax_scale=None, peak_norm=False,
the function call to suppress the display of the return value.
"""
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

data = self.data.copy()
if deltas:
Expand Down Expand Up @@ -156,7 +157,8 @@ def plot_grid(self, *, ax=None, vmax_scale=None, peak_norm=False,
nxpsfs = self._xgrid.shape[0]
extent = [-0.5, nxpsfs - 0.5, -0.5, nypsfs - 0.5]

ax.imshow(data, extent=extent, norm=norm, cmap=cmap, origin='lower')
axim = ax.imshow(data, extent=extent, norm=norm, cmap=cmap,
origin='lower')

# Use the axes set up above to set appropriate tick labels
xticklabels = self._xgrid.astype(int)
Expand All @@ -172,9 +174,9 @@ def plot_grid(self, *, ax=None, vmax_scale=None, peak_norm=False,
ax.set_ylabel('ePSF location in detector Y pixels')

if dividers:
for ix in range(nxpsfs):
for ix in range(nxpsfs - 1):
ax.axvline(ix + 0.5, color=divider_color, ls=divider_ls)
for iy in range(nypsfs):
for iy in range(nypsfs - 1):
ax.axhline(iy + 0.5, color=divider_color, ls=divider_ls)

instrument = self.meta.get('instrument', '')
Expand Down Expand Up @@ -211,7 +213,10 @@ def plot_grid(self, *, ax=None, vmax_scale=None, peak_norm=False,
else:
label = 'ePSF flux per pixel'

cbar = plt.colorbar(label=label, mappable=ax.images[0])
divider = make_axes_locatable(ax)
cax_cbar = divider.append_axes('right', size='3%', pad='3%')
cbar = fig.colorbar(axim, cax=cax_cbar, label=label)

if not deltas:
cbar.ax.set_yscale('log')

Expand Down

0 comments on commit d73bfb7

Please sign in to comment.