-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlook.py
31 lines (29 loc) · 1.02 KB
/
look.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
import matplotlib.cm as cm
from matplotlib import pyplot as plt
def look(img, range=None, x_range=None, y_range=None):
"""Simple function to wrap matplotlib and display an image with a colorbar."""
plt.figure(figsize=(8, 6))
if range is None:
range = [np.min(img), np.max(img)]
img_use = np.clip(img, range[0], range[1])
if x_range is not None:
x0 = int(x_range[0])
x1 = int(x_range[1])
if x0 < 0:
img_use = np.roll(img_use, -x0, axis=1)
x1 -= x0
x0 = 0
img_use = img_use[:, x0: x1]
if y_range is not None:
y0 = int(y_range[0])
y1 = int(y_range[1])
if y0 < 0:
img_use = np.roll(img_use, -y0, axis=0)
y1 -= y0
y0 = 0
img_use = img_use[y0: y1, :]
fig_show = plt.imshow(img_use, interpolation='none', origin='lower', cmap=cm.rainbow)
plt.colorbar(fig_show, orientation='vertical', shrink=1)
# cbar.set_label('DCR (arcsec)', labelpad=0)
plt.show()