35 KiB
35 KiB
In [1]:
%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
from random import random, seed
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make data.
x = np.arange(0, 1, 0.05)
y = np.arange(0, 1, 0.05)
x, y = np.meshgrid(x,y)
def FrankeFunction(x,y):
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
return term1 + term2 + term3 + term4
z = FrankeFunction(x, y)
# Plot the surface.
surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-0.10, 1.40)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()[0;31m---------------------------------------------------------------------------[0m [0;31mTypeError[0m Traceback (most recent call last) Cell [0;32mIn[1], line 11[0m [1;32m 8[0m [38;5;28;01mfrom[39;00m [38;5;21;01mrandom[39;00m [38;5;28;01mimport[39;00m random, seed [1;32m 10[0m fig [38;5;241m=[39m plt[38;5;241m.[39mfigure() [0;32m---> 11[0m ax [38;5;241m=[39m [43mfig[49m[38;5;241;43m.[39;49m[43mgca[49m[43m([49m[43mprojection[49m[38;5;241;43m=[39;49m[38;5;124;43m'[39;49m[38;5;124;43m3d[39;49m[38;5;124;43m'[39;49m[43m)[49m [1;32m 13[0m [38;5;66;03m# Make data.[39;00m [1;32m 14[0m x [38;5;241m=[39m np[38;5;241m.[39marange([38;5;241m0[39m, [38;5;241m1[39m, [38;5;241m0.05[39m) [0;31mTypeError[0m: gca() got an unexpected keyword argument 'projection'
<Figure size 640x480 with 0 Axes>
In [2]:
scipy.misc.imreadIn [3]:
import numpy as np
from imageio import imread
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
# Load the terrain
terrain1 = imread('SRTM_data_Norway_1.tif')
# Show the terrain
plt.figure()
plt.title('Terrain over Norway 1')
plt.imshow(terrain1, cmap='gray')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()