Skip to content

Instantly share code, notes, and snippets.

@leomao
Created April 26, 2014 15:08
Show Gist options
  • Save leomao/11322469 to your computer and use it in GitHub Desktop.
Save leomao/11322469 to your computer and use it in GitHub Desktop.
3dplot
#! /usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
file = open("map1.txt")
n = int(file.readline()) + 1
hei = []
for line in file:
hei.append([float(x) for x in line.strip().split()])
Z = np.array(hei).reshape((n, n))
x = range(n)
X, Y = np.meshgrid(x, x)
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm)
plt.colorbar(surf, shrink=0.7)
plt.show()
im = plt.imshow(Z, cmap=cm.coolwarm)
plt.colorbar(im, shrink=0.7)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment