How to plot this 3D graph from excel using matplotlib

100 Views Asked by At

I have attached a graph: This is a graph from excel

I want to create the same graph using code in matplotlib. I checked online for 3d graphs but didn't get anything similar to this.

This is the data that needs to be plotted In the above picture, Data1, Data2, Data3 must be in the x-axis. V1, V2, V3 in the z-axis and the values in the y-axis

Does anyone know how to do that?

1

There are 1 best solutions below

3
MB-44 On

We have to use Axes3D and art3d modules.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D, art3d

# Extract data from Excel file or spreadsheet
x, y, z, colors = ...

# Create pyramid objects
pyramids = []
for i in range(len(x)):
    pyramid = art3d.Pyramid()
    pyramid.set_verts([(x[i], y[i], z[i]),
                  (x[i] + 0.5, y[i], z[i]),
                  (x[i], y[i] + 0.5, z[i]),
                  (x[i] - 0.5, y[i], z[i]),
                  (x[i], y[i], z[i] + 1)])
    pyramid.set_color(colors[i])
    pyramids.append(pyramid)

# Create plot and customize
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Add pyramids to plot
for pyramid in pyramids:
    ax.add_artist(pyramid)

# Set labels, title, and adjust view
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
plt.title('3D Scatter Plot of Pyramids')
ax.view_init(elev=15, azim=-60)

# Show the plot
plt.show()