Created
April 26, 2014 15:08
-
-
Save leomao/11322469 to your computer and use it in GitHub Desktop.
3dplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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