Skip to content

Commit

Permalink
Rename fig= to figure= in TiledDataset.plot (#509)
Browse files Browse the repository at this point in the history
* Rename ``fig=`` to ``figure=`` in ``TiledDataset.plot``

* Modify old changelog

* Fix the test
  • Loading branch information
Cadair authored Jan 29, 2025
1 parent 663184f commit e34b1c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion changelog/491.feature.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add a ``fig=`` keyword argument to `TiledDataset.plot` and make it default to the current figure.
Add a ``figure=`` keyword argument to `TiledDataset.plot` and make it default to the current figure.
2 changes: 1 addition & 1 deletion dkist/dataset/tests/test_tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_tileddataset_plot(share_zscale):
tile.meta["inventory"] = ori_ds.inventory
ds = TiledDataset(np.array(newtiles).reshape(ori_ds.shape), inventory=newtiles[0].inventory)
fig = plt.figure(figsize=(12, 15))
ds.plot(0, share_zscale=share_zscale, fig=fig)
ds.plot(0, share_zscale=share_zscale, figure=fig)
return plt.gcf()


Expand Down
20 changes: 10 additions & 10 deletions dkist/dataset/tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _get_axislabels(ax):
ylabel = coord.get_axislabel() or coord._get_default_axislabel()
return (xlabel, ylabel)

def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
def plot(self, slice_index, share_zscale=False, figure=None, **kwargs):
"""
Plot a slice of each tile in the TiledDataset
Expand All @@ -181,32 +181,32 @@ def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
Determines whether the color scale of the plots should be calculated
independently (``False``) or shared across all plots (``True``).
Defaults to False
fig : `matplotlib.figure.Figure`
figure : `matplotlib.figure.Figure`
A figure to use for the plot. If not specified the current pyplot
figure will be used, or a new one created.
"""
if isinstance(slice_index, int):
slice_index = (slice_index,)
vmin, vmax = np.inf, 0

if fig is None:
fig = plt.gcf()
if figure is None:
figure = plt.gcf()

tiles = self.slice_tiles[slice_index].flat
for i, tile in enumerate(tiles):
ax = fig.add_subplot(self.shape[0], self.shape[1], i+1, projection=tile.wcs)
ax = figure.add_subplot(self.shape[0], self.shape[1], i+1, projection=tile.wcs)
tile.plot(axes=ax, **kwargs)
if i == 0:
xlabel, ylabel = self._get_axislabels(ax)
fig.supxlabel(xlabel, y=0.05)
fig.supylabel(ylabel, x=0.05)
figure.supxlabel(xlabel, y=0.05)
figure.supylabel(ylabel, x=0.05)
axmin, axmax = ax.get_images()[0].get_clim()
vmin = axmin if axmin < vmin else vmin
vmax = axmax if axmax > vmax else vmax
ax.set_ylabel(" ")
ax.set_xlabel(" ")
if share_zscale:
for ax in fig.get_axes():
for ax in figure.get_axes():
ax.get_images()[0].set_clim(vmin, vmax)
title = f"{self.inventory['instrumentName']} Dataset ({self.inventory['datasetId']}) at "
for i, (coord, val) in enumerate(list(tiles[0].global_coords.items())[::-1]):
Expand All @@ -216,8 +216,8 @@ def plot(self, slice_index, share_zscale=False, fig=None, **kwargs):
val = val.symbol
title += f"{coord} {val}" + (", " if i != len(slice_index)-1 else " ")
title += f"(slice={(slice_index if len(slice_index) > 1 else slice_index[0])})".replace("slice(None, None, None)", ":")
fig.suptitle(title, y=0.95)
return fig
figure.suptitle(title, y=0.95)
return figure

@property
def slice_tiles(self):
Expand Down

0 comments on commit e34b1c5

Please sign in to comment.