Black Lives Matter. Please consider donating to Black Girls Code today.

# 3D Cone Plots in Python

How to make 3D Cone plots in Python with Plotly.

New to Plotly?

Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

A cone plot is the 3D equivalent of a 2D quiver plot, i.e., it represents a 3D vector field using cones to represent the direction and norm of the vectors. 3-D coordinates are given by x, y and z, and the coordinates of the vector field by u, v and w.

### Basic 3D Cone¶

In :
import plotly.graph_objects as go

fig = go.Figure(data=go.Cone(x=, y=, z=, u=, v=, w=))

fig.update_layout(scene_camera_eye=dict(x=-0.76, y=1.8, z=0.92))

fig.show()


### Multiple 3D Cones¶

In :
import plotly.graph_objects as go

fig = go.Figure(data=go.Cone(
x=[1, 2, 3],
y=[1, 2, 3],
z=[1, 2, 3],
u=[1, 0, 0],
v=[0, 3, 0],
w=[0, 0, 2],
sizemode="absolute",
sizeref=2,
anchor="tip"))

fig.update_layout(
scene=dict(domain_x=[0, 1],
camera_eye=dict(x=-1.57, y=1.36, z=0.58)))

fig.show()


### 3D Cone Lighting¶

In :
import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Cone(x=[8,] * 3, lightposition=dict(x=0, y=0, z=1e5),
name="lighting.position x:0,y:0,z:1e5"))

fig.update_traces(y=[1, 2, 3], z=[1, 1, 1],
u=[1, 2, 3], v=[1, 1, 2], w=[4, 4, 1],
hoverinfo="u+v+w+name",
showscale=False)

fig.update_layout(scene=dict(aspectmode="data",
camera_eye=dict(x=0.05, y=-2.6, z=2)),
margin=dict(t=0, b=0, l=0, r=0))

fig.show()


### 3D Cone Vortex¶

In :
import plotly.graph_objects as go
import pandas as pd

fig = go.Figure(data = go.Cone(
x=df['x'],
y=df['y'],
z=df['z'],
u=df['u'],
v=df['v'],
w=df['w'],
colorscale='Blues',
sizemode="absolute",
sizeref=40))

fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=0.8),
camera_eye=dict(x=1.2, y=1.2, z=0.6)))

fig.show()


#### Reference¶

Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.

Learn about how to install Dash at https://dash.plot.ly/installation.

Everywhere in this page that you see fig.show(), you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:

import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.update_layout( ... )

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
]) 