Skip to content

Instantly share code, notes, and snippets.

@dkirkby
Last active July 2, 2020 15:00
Show Gist options
  • Save dkirkby/d83df824a435c6ea6c2c22941322a9be to your computer and use it in GitHub Desktop.
Save dkirkby/d83df824a435c6ea6c2c22941322a9be to your computer and use it in GitHub Desktop.
Plot an image without any pixel resampling
def plot_pixels(D, zoom=1, dpi=64, x0=0, y0=0, **args):
ny, nx = D.shape
width, height = zoom * nx, zoom * ny
fig = plt.figure(figsize=(width / dpi, height / dpi), dpi=dpi, frameon=False)
ax = plt.axes((0, 0, 1, zoom * ny / height))
extent = [x0 - 0.5, x0 + nx - 0.5, y0 - 0.5, y0 + ny - 0.5]
ax.imshow(D, extent=extent, **args)
ax.axis('off')
return fig, ax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment