#371 Surface plot

#371 3D surface plot

3D plots are awesome to make surface plots. In a surface plot, each point is defined by 3 points: its latitude, its longitude, and its altitude (X, Y and Z). Thus, 2 types of input are possible. i/ A rectangular matrix where each cell represents the altitude. ii/ A long format matrix with 3 columns where each row is a point. This example use the rectangular format as an input, transform it to a long format, and make the plot:


# 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

# And transform the old column name in something numeric

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

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

# Rotate it
ax.view_init(30, 45)

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


  • Sponsors


    • Hello,
      I’m Kurniawan from Indonesia and I do research for my study about 3d plotting geographical terrain from multiple images.

      Your research was very helpful to me.
      I wanna ask about how you can get the array data on your CSV file? is that random data or you make some algorithm to convert image into array and save it into CSV file?

      Regards, Kurniawan

    • Hello, how is it possible to use custom made axes? For example, if have X-values (1,5,10) and Y-values (1,2,3,4,5,6,7,8,9,10) in a full factorial design.


    Leave a Reply

    Your email address will not be published.