How to make 3D subplots using plotly?

This recipe helps you make 3D subplots using plotly

Recipe Objective

Make 3D subplots using plotly

Plotly gives a function through which we can make subplots. Lets understand this practically.

Step 1 - Import libraries

import plotly.graph_objects as go from plotly.subplots import make_subplots import numpy as np

Step 2 - Initialize subplots

fig = make_subplots( rows=2, cols=2, specs=[[{'type': 'surface'}, {'type': 'surface'}], [{'type': 'surface'}, {'type': 'surface'}]])

Here we are initializing figure with 4 3D subplots

Step 3 - Generate the Data

Data_x = np.linspace(-5, 80, 10) Data_y = np.linspace(-5, 60, 10) xGrid, yGrid = np.meshgrid(Data_y, Data_x) Data_z = xGrid ** 3 + yGrid ** 3

Step 4 - Plot graph

fig.add_trace( go.Surface(x=Data_x, y=Data_y, z=Data_z, colorscale='Viridis', showscale=False), row=1, col=1) fig.add_trace( go.Surface(x=Data_x, y=Data_y, z=Data_z, colorscale='RdBu', showscale=False), row=1, col=2) fig.add_trace( go.Surface(x=Data_x, y=Data_y, z=Data_z, colorscale='YlOrRd', showscale=False), row=2, col=1) fig.add_trace( go.Surface(x=Data_x, y=Data_y, z=Data_z, colorscale='YlGnBu', showscale=False), row=2, col=2) fig.update_layout( title_text='Differnt 3D subplots with different color scale', height=900, width=900 ) fig.show()

Here we are adding surfaces to the subplots and then plotting them

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Learn to Build a Neural network from Scratch using NumPy
In this deep learning project, you will learn to build a neural network from scratch using NumPy

Credit Card Default Prediction using Machine learning techniques
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Build PowerBI Dashboard for Water Quality Sensor Data Analysis
In this PowerBI Project, you will learn to build a PowerBI Dashboard to analyze and visualize water quality sensor data from various European countries.

End-to-End Snowflake Healthcare Analytics Project on AWS-1
In this Snowflake Healthcare Analytics Project, you will leverage Snowflake on AWS to predict patient length of stay (LOS) in hospitals. The prediction of LOS can help in efficient resource allocation, lower the risk of staff/visitor infections, and improve overall hospital functioning.

Linear Regression Model Project in Python for Beginners Part 1
Machine Learning Linear Regression Project in Python to build a simple linear regression model and master the fundamentals of regression for beginners.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.