python - 山蟒的 3D 表面图

标签 python matplotlib google-earth surface mplot3d

我正在尝试重现代表山脉轮廓的 3d 表面图。我知道我必须创建一个 csv 文件来读取代码,并且我正在尝试从 google earth 获取坐标。有人可以建议一种方法吗?是否有执行此类工作的代码? 我正在尝试遵循此代码:

# library
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

# Get the data (csv file is hosted on the web)
url = 'https://python-graph-gallery.com/wp-content/uploads/volcano.csv'
data = pd.read_csv(url)

# Transform it to a long format
df=data.unstack().reset_index()
df.columns=["X","Y","Z"]

# And transform the old column name in something numeric
df['X']=pd.Categorical(df['X'])
df['X']=df['X'].cat.codes

# Make the plot
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(df['Y'], df['X'], df['Z'], cmap=plt.cm.viridis, 
linewidth=0.2)
plt.show()

# to Add a color bar which maps values to colors.
surf=ax.plot_trisurf(df['Y'], df['X'], df['Z'], cmap=plt.cm.viridis, 
linewidth=0.2)
fig.colorbar( surf, shrink=0.5, aspect=5)
plt.show()

# Rotate it
ax.view_init(30, 45)
plt.show()

# Other palette
ax.plot_trisurf(df['Y'], df['X'], df['Z'], cmap=plt.cm.jet, linewidth=0.01)
plt.show()

谢谢大家

最佳答案

问题是由于 ssl 身份验证错误,将脚本的头部替换为:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import requests
from io import StringIO

# Get the data (csv file is hosted on the web)
url = 'https://python-graph-gallery.com/wp-content/uploads/volcano.csv'
r1 = requests.get(url, verify=False)
data = pd.read_csv(StringIO(r1.text))  # works
...

在此代码中,不检查 ssl 证书。 enter image description here

关于python - 山蟒的 3D 表面图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53722001/

相关文章:

python datetime fromtimestamp 产生值错误年份超出范围

python - 更改 wxPython TextCtrl 小部件上的字体

python - 如何删除没有内容的标签

python - 在 python matplotlib.dates 中绘制毫秒图

gis - 有没有办法将 map 划分为方形网格并从那里检索纬度/经度信息?

java - 如何使用 Java 在 KML 中标记多个坐标?

javascript - 无法将 HTML 输入到 JS

python - IPython 键盘中断 CTRL + C 不一致

numpy - 用不同的标记 python 绘制类

maps - KML + 谷歌地球 : Fill a quadrilateral with a bitmap?