<jupyter_start><jupyter_text>[3D plots](https://python-graph-gallery.com/3d/) are awesome to make **surface plots**. In a surface plot, each point is defined by 3 variables: its **latitude**, its **longitude**, and its **altitude** (X, Y and Z). Thus, 2 types of **inputs** are possible:1) A rectangular matrix where each cell represents the altitude.  2) A long format matrix with 3 columns where each row is a point.  This example uses the rectangular format as an input, transforms it to a long format, and makes the plot:<jupyter_code># libraries
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://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/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.
fig = plt.figure()
ax = fig.gca(projection='3d')
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
fig = plt.figure()
ax = fig.gca(projection='3d')
surf=ax.plot_trisurf(df['Y'], df['X'], df['Z'], cmap=plt.cm.viridis, linewidth=0.2)
ax.view_init(30, 45)
plt.show()
 
# Other palette
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(df['Y'], df['X'], df['Z'], cmap=plt.cm.jet, linewidth=0.01)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16758849557522124, 'fraction_numerical': 0.016039823008849558, 'mean_word_length': 5.216494845360825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '605830', 'license': '0BSD', 'n_tokens_mistral': 706, 'n_tokens_neox': 670, 'n_words': 192, 'path': 'src/notebooks/371-surface-plot.ipynb', 'repo_name': 's-lasch/The-Python-Graph-Gallery', 'size': '1808'}