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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build a Text Classification Model with Attention Mechanism NLP
In this NLP Project, you will learn to build a multi class text classification model with attention mechanism.

Deep Learning Project for Time Series Forecasting in Python
Deep Learning for Time Series Forecasting in Python -A Hands-On Approach to Build Deep Learning Models (MLP, CNN, LSTM, and a Hybrid Model CNN-LSTM) on Time Series Data.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.