基于Rasterio与matplotlib的DEM三维展示
2017-06-04 16:55
363 查看
直接上代码了
>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import rasterio as rio
>>> f=rio.open(r'C:\Users\suns\Desktop\Ex1\dem')
>>> nrows=f.height
>>> nrows
327
>>> ncols=f.width
>>> Xmin=f.bounds.left
>>> Xmin
442189.26993154
>>> Xmax=f.bounds.right
>>> Xmax
444619.26993154
>>> Ymin=f.bounds.bottom
>>> Ymin
4161425.3140877
>>> Ymax=f.bounds.top
>>> Ymax
4163060.3140877
>>> x = np.linspace(Xmin,Xmax, ncols)
>>> y = np.linspace(Ymin,Ymax, nrows)
>>> X,Y = np.meshgrid(x, y)
>>> Z=f.read(1)
>>> print(Z)
[[ 1018.3137207 1021.53942871 1025.41796875 ..., 1079.36437988
1077.99060059 1075.89050293]
[ 1019.75012207 1023.7064209 1027.79187012 ..., 1082.44714355
1079.32910156 1077.33557129]
[ 1021.66424561 1025.62988281 1029.59558105 ..., 1085.37890625
1081.47424316 1079.17553711]
...,
[ 995.26403809 994.10968018 992.90063477 ..., 1112.69433594
1113.80249023 1114.9107666 ]
[ 999.4006958 998.52185059 997.52252197 ..., 1114.14465332
1115.0213623 1116.12963867]
[ 1003.53076172 1002.79931641 1001.77233887 ..., 1115.82263184
1116.56359863 1117.34851074]]
>>> region = np.s_[10:400,10:400]
>>> X, Y, Z = X[region], Y[region],Z[region]
>>> fig = plt.figure()
>>> ax = Axes3D(fig)
>>> ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x0000000004F88940>
>>> plt.show()
>>>
>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import rasterio as rio
>>> f=rio.open(r'C:\Users\suns\Desktop\Ex1\dem')
>>> nrows=f.height
>>> nrows
327
>>> ncols=f.width
>>> Xmin=f.bounds.left
>>> Xmin
442189.26993154
>>> Xmax=f.bounds.right
>>> Xmax
444619.26993154
>>> Ymin=f.bounds.bottom
>>> Ymin
4161425.3140877
>>> Ymax=f.bounds.top
>>> Ymax
4163060.3140877
>>> x = np.linspace(Xmin,Xmax, ncols)
>>> y = np.linspace(Ymin,Ymax, nrows)
>>> X,Y = np.meshgrid(x, y)
>>> Z=f.read(1)
>>> print(Z)
[[ 1018.3137207 1021.53942871 1025.41796875 ..., 1079.36437988
1077.99060059 1075.89050293]
[ 1019.75012207 1023.7064209 1027.79187012 ..., 1082.44714355
1079.32910156 1077.33557129]
[ 1021.66424561 1025.62988281 1029.59558105 ..., 1085.37890625
1081.47424316 1079.17553711]
...,
[ 995.26403809 994.10968018 992.90063477 ..., 1112.69433594
1113.80249023 1114.9107666 ]
[ 999.4006958 998.52185059 997.52252197 ..., 1114.14465332
1115.0213623 1116.12963867]
[ 1003.53076172 1002.79931641 1001.77233887 ..., 1115.82263184
1116.56359863 1117.34851074]]
>>> region = np.s_[10:400,10:400]
>>> X, Y, Z = X[region], Y[region],Z[region]
>>> fig = plt.figure()
>>> ax = Axes3D(fig)
>>> ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x0000000004F88940>
>>> plt.show()
>>>
相关文章推荐
- 基于matplotlib的数据可视化 - 三维曲面图gca
- Python基于matplotlib实现绘制三维图形功能示例
- 7057-1.Python数据可视化:利用matplotlib中的subplot进行图中图展示
- Python-Matplotlib(4) 基于真实数据集的可视化分析
- Matplotlib Toolkits:三维绘图工具包matplotlib.mplot3d
- 凡哥OpenCV基础入门教程(跳一跳专题)-CH1.2_通过Matplotlib展示图片
- 基于 Python Matplotlib 模块的高质量图形输出
- matplotlib绘制三维图
- 基于Anaconda的tensorflow/jupyter notebook/numpy/matplotlib/scipy的安装
- 基于matplotlib的数据可视化(图形填充fill fill_between) - 笔记(二)
- matplotlib 画图 三维图
- 一步一步kmeans算法研究--numpy及matplotlib原始数据读取与展示
- 基于matplotlib的数据可视化 - 柱状图bar
- 安装基于Python3 的NumPy, SciPy, matplotlib和Scikit-Learn
- Python使用matplotlib绘制三维曲线
- 基于 Python Matplotlib 模块的高质量图形输出
- 基于官方教程的matplotlib简介
- Python使用matplotlib绘制三维图形示例
- python matplotlib模块——绘制三维图形、三维数据散点图
- 【Python】Matplotlib画图(十)——基于networkx画关系网络图