Skip to content

Commit 815e61c

Browse files
authored
Merge pull request #319 from openspyrit/stat
Stat
2 parents e4116de + 79e0d18 commit 815e61c

File tree

2 files changed

+131
-334
lines changed

2 files changed

+131
-334
lines changed

spyrit/misc/disp.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def imagesc(
150150
colormap=None,
151151
show=True,
152152
figsize=None,
153+
fig=None,
154+
ax=None,
153155
cbar_pos=None,
154156
title_fontsize=16,
155157
**kwargs,
@@ -190,29 +192,27 @@ def imagesc(
190192

191193
if colormap is None:
192194
colormap = plt.cm.gray
195+
193196
elif isinstance(colormap, numbers.Number):
194197
if "gamma" in kwargs:
195198
gamma = kwargs["gamma"]
196199
else:
197200
gamma = 0.6
198201
colormap = wavelength_to_colormap(colormap, gamma=gamma)
199202

200-
fig = plt.figure(figsize=figsize)
201-
ax = fig.add_subplot(1, 1, 1)
202-
plt.imshow(Img, cmap=colormap)
203-
plt.title(title, fontsize=title_fontsize)
204-
divider = make_axes_locatable(ax)
203+
if fig is None:
204+
fig = plt.figure(figsize=figsize)
205205

206-
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
206+
if ax is None:
207+
ax = fig.add_subplot(1, 1, 1)
208+
209+
pos = ax.imshow(Img, cmap=colormap)
207210

208211
if cbar_pos == "bottom":
209-
cax = inset_axes(
210-
ax, width="100%", height="5%", loc="lower center", borderpad=-5
211-
)
212-
plt.colorbar(cax=cax, orientation="horizontal")
212+
fig.colorbar(pos, ax=ax, location="bottom", orientation="horizontal")
213213
else:
214-
cax = plt.axes([0.85, 0.1, 0.075, 0.8])
215-
plt.colorbar(cax=cax, orientation="vertical")
214+
fig.colorbar(pos, ax=ax, location="right", orientation="vertical")
215+
ax.set_title(title, fontsize=title_fontsize)
216216

217217
# fig.tight_layout() # it raises warnings in some cases
218218
if show is True:

0 commit comments

Comments
 (0)