Skip to content

Instantly share code, notes, and snippets.

@geggo
Created August 2, 2017 20:57
Show Gist options
  • Save geggo/d2e3d300c09b7051559172918ecc9eba to your computer and use it in GitHub Desktop.
Save geggo/d2e3d300c09b7051559172918ecc9eba to your computer and use it in GitHub Desktop.
#notes: figure out matplotlib/agg image interpolation
# start with src/_image_resample.h:resample(...)
# agg_span_image_filter_gray.h / very end: -> clipping
import matplotlib as mpl
mpl.use('agg')
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.image as mimage
import matplotlib.cm as mcm
import numpy as np
import copy
#cm = copy.copy(mcm.get_cmap('viridis'))
cm = copy.copy(mcm.get_cmap('gray'))
cm.set_over('r')
cm.set_under('c')
cm.set_bad('k')
n = mcolors.Normalize(vmin=0, vmax=100)
data = np.arange(100, dtype='float').reshape(10, 10)
data[7, 3] = -10
data[3, 7] = 200
data[3, 8] = -100
data[7, 7] = 110
data[9, 0] = 101
data[3,3] = 1000
#data[3, 3] = np.nan
#data[5, 3] = np.inf
mask = np.zeros_like(data).astype('bool')
#mask[3, 5] = True
data = np.ma.masked_array(data, mask)
fig, ax_grid = plt.subplots(3, 6, figsize=(12,6))
for interp, ax in zip(mimage._interpd_, ax_grid.ravel()):
ax.set_title(interp)
im = ax.imshow(data, norm=n, cmap=cm, interpolation=interp)
ax.axis('off')
plt.tight_layout( )
plt.savefig('test_interpolation_8024.png', dpi=72)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment