In [1]:
%pylab qt
import pylab as plt
import numpy as np
from yoink.widgets import ShutterCrop, DragableColorLine
from yoink.interp import invert_cmap
In [7]:
clf()
X = np.linspace(-1, 1, 100)
Y = np.linspace(-2, 1, 100)
X, Y = np.meshgrid(X, Y)
Z = np.hypot(X-Y, 3*X+Y*X)
plt.pcolormesh(X, Y, Z, cmap=plt.cm.jet_r)
plt.clim(0, 5)
plt.colorbar()
Out[7]:
In [8]:
plt.savefig('cmap.png')
img = plt.imread('cmap.png')
In [9]:
imshow(img)
Out[9]:
In [10]:
plt.figure(2)
plt.clf()
plt.imshow(img)
cropper = ShutterCrop(plt.gca())
plt.title('Cropping')
Out[10]:
In [11]:
ext = cropper.get_extents()
j0, jx = sorted(ext[:2])
i0, ix = sorted(ext[2:])
img_crop = img[i0:ix+1, j0:jx+1]
In [12]:
figure(4)
imshow(img_crop)
Out[12]:
In [13]:
plt.figure(42)
fake_ax = subplot(111)
plt.figure(3)
plt.clf()
plt.imshow(img)
xl = plt.xlim()
yl = plt.ylim()
cbar_select = DragableColorLine(plt.gca(), fake_ax, img)
plt.xlim(*xl)
plt.ylim(*yl)
Out[13]:
In [14]:
plt.plot(cbar_select.l, cbar_select.rgb[:, 0], 'r')
plt.plot(cbar_select.l, cbar_select.rgb[:, 1], 'g')
plt.plot(cbar_select.l, cbar_select.rgb[:, 2], 'b')
Out[14]:
In [23]:
z = invert_cmap(img_crop, cbar_select.l, cbar_select.rgb)
zmin, zmax = 0, 5 # from colorbar
z = zmin + z*(zmax-zmin)
ny, nx = z.shape
xmin, xmax = -1, 1
ymin, ymax = 2, -2 # PNGs index top to bottom
x = np.linspace(xmin, xmax, nx)
y = np.linspace(ymin, ymax, ny)
In [24]:
figure(10)
clf()
subplot(121)
pcolormesh(X, Y, Z, cmap=plt.cm.jet_r)
clim(0, 5)
subplot(122)
pcolormesh(x, y, z, cmap=plt.cm.jet_r)
Out[24]:
In [ ]: