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

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch