Skip to content

Instantly share code, notes, and snippets.

@alisterburt
Last active May 7, 2024 17:24
Show Gist options
  • Save alisterburt/d48142744fca6a696bc9a33f782ad18c to your computer and use it in GitHub Desktop.
Save alisterburt/d48142744fca6a696bc9a33f782ad18c to your computer and use it in GitHub Desktop.
matplotlib gradient overlays - gradient resolution is different from image resolution
import matplotlib.pyplot as plt
import numpy as np
from cmap import Colormap
h, w = 512, 868
image = np.random.random(size=(h, w))
defocus = np.array([[0, 1],
[1, 0]])
fig, ax = plt.subplots()
ax.imshow(image, cmap='gray')
cm = Colormap('tol:BuRd').to_mpl()
ax.imshow(defocus, extent=(-0.5, w-0.5, h-0.5, -0.5), alpha=0.3, interpolation='spline36', cmap=cm)
plt.show()
@alisterburt
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment