Skip to content

Instantly share code, notes, and snippets.

@dengemann
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dengemann/9081fc259ee5d03ffc6a to your computer and use it in GitHub Desktop.
Save dengemann/9081fc259ee5d03ffc6a to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches
rmax = 0.5
step = 2 * np.pi / 101
l = np.arange(0, 2 * np.pi + step, step)
x = np.cos(l) * rmax
y = np.sin(l) * rmax
hlim = (-0.5, 0.5)
vlim = (-0.5, 0.5)
fig, ax = plt.subplots(1, 1)
rng = np.random.RandomState(75)
data = rng.random_sample((100, 100))
ax.plot(x, y, color='k')
im = ax.imshow(data, extent=[hlim[0], hlim[1], vlim[0], vlim[1]],
origin='lower', cmap='RdBu_r', interpolation='nearest')
patch = patches.Circle((0.5, 0.5), radius=0.5, clip_on=True,
transform=ax.transAxes)
fig.set_clip_path(patch)
im.set_clip_path(patch)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment