Steren
Steren

Reputation: 127

3D surface plot of a mountain python

I'm trying to reproduce a 3d surface plot that represents the profile of a mountain. I understand that I have to create a csv file to read in the code, and I'm trying to get the coordinates from google earth. could someone suggest a way? is there a code that does this kind of work? I'm trying to follow this code:

# 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()

thank you all

Upvotes: 3

Views: 3632

Answers (1)

pcu
pcu

Reputation: 1214

The issue come because of error in ssl authentication, replace head of your script by:

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
...

In this code the ssl certificate does not check. enter image description here

Upvotes: 3

Related Questions