Skip to content

Instantly share code, notes, and snippets.

@BenedictWilkins
Created October 25, 2019 14:53
Show Gist options
  • Save BenedictWilkins/d71ff0c462d39d8dc59a0dbe7411224f to your computer and use it in GitHub Desktop.
Save BenedictWilkins/d71ff0c462d39d8dc59a0dbe7411224f to your computer and use it in GitHub Desktop.
Plot an Image in 3D with pyplot
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 24 19:33:19 2019
Plot an image in 3D using pyplot.
Assumes image is grayscale and in HWC format.
@author: Benedict Wilkins
"""
import matplotlib.pyplot as plt
import numpy as np
img = np.random.uniform(size=(10,10,1))
X = np.arange(0, img.shape[1])
Y = np.arange(0, img.shape[0])
X, Y = np.meshgrid(X, Y)
Z = img.squeeze()
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment