|
| 1 | +--- |
| 2 | +jupyter: |
| 3 | + jupytext: |
| 4 | + notebook_metadata_filter: all |
| 5 | + text_representation: |
| 6 | + extension: .md |
| 7 | + format_name: markdown |
| 8 | + format_version: '1.1' |
| 9 | + jupytext_version: 1.2.3 |
| 10 | + kernelspec: |
| 11 | + display_name: Python 3 |
| 12 | + language: python |
| 13 | + name: python3 |
| 14 | + language_info: |
| 15 | + codemirror_mode: |
| 16 | + name: ipython |
| 17 | + version: 3 |
| 18 | + file_extension: .py |
| 19 | + mimetype: text/x-python |
| 20 | + name: python |
| 21 | + nbconvert_exporter: python |
| 22 | + pygments_lexer: ipython3 |
| 23 | + version: 3.7.3 |
| 24 | + plotly: |
| 25 | + description: How to make 3D Cone plots in Python with Plotly. |
| 26 | + display_as: 3d_charts |
| 27 | + has_thumbnail: true |
| 28 | + ipynb: ~notebook_demo/206 |
| 29 | + language: python |
| 30 | + layout: user-guide |
| 31 | + name: 3D Cone Plots |
| 32 | + order: 20 |
| 33 | + page_type: u-guide |
| 34 | + permalink: python/cone-plot/ |
| 35 | + redirect_from: python/3d-cone/ |
| 36 | + thumbnail: thumbnail/3dcone.png |
| 37 | + title: 3D Cone Plots | Plotly |
| 38 | +--- |
| 39 | + |
| 40 | +A cone plot is the 3D equivalent of a 2D [quiver plot](./quiver-plots/), 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`. |
| 41 | + |
| 42 | +### Basic 3D Cone |
| 43 | + |
| 44 | + |
| 45 | +```python |
| 46 | +import plotly.graph_objects as go |
| 47 | + |
| 48 | +fig = go.Figure(data=go.Cone(x=[1], y=[1], z=[1], u=[1], v=[1], w=[0])) |
| 49 | + |
| 50 | +fig.update_layout(scene_camera_eye=dict(x=-0.76, y=1.8, z=0.92)) |
| 51 | + |
| 52 | +fig.show() |
| 53 | +``` |
| 54 | + |
| 55 | +### Multiple 3D Cones |
| 56 | + |
| 57 | +```python |
| 58 | +import plotly.graph_objects as go |
| 59 | + |
| 60 | +fig = go.Figure(data=go.Cone( |
| 61 | + x=[1, 2, 3], |
| 62 | + y=[1, 2, 3], |
| 63 | + z=[1, 2, 3], |
| 64 | + u=[1, 0, 0], |
| 65 | + v=[0, 3, 0], |
| 66 | + w=[0, 0, 2], |
| 67 | + sizemode="absolute", |
| 68 | + sizeref=2, |
| 69 | + anchor="tip")) |
| 70 | + |
| 71 | +fig.update_layout( |
| 72 | + scene=dict(domain_x=[0, 1], |
| 73 | + camera_eye=dict(x=-1.57, y=1.36, z=0.58))) |
| 74 | + |
| 75 | +fig.show() |
| 76 | +``` |
| 77 | + |
| 78 | +### 3D Cone Lighting |
| 79 | + |
| 80 | +```python |
| 81 | +import plotly.graph_objects as go |
| 82 | + |
| 83 | +fig = go.Figure() |
| 84 | +fig.add_trace(go.Cone(x=[1,] * 3, name="base")) |
| 85 | +fig.add_trace(go.Cone(x=[2,] * 3, opacity=0.3, name="opacity:0.3")) |
| 86 | +fig.add_trace(go.Cone(x=[3,] * 3, lighting_ambient=0.3, name="lighting.ambient:0.3")) |
| 87 | +fig.add_trace(go.Cone(x=[4,] * 3, lighting_diffuse=0.3, name="lighting.diffuse:0.3")) |
| 88 | +fig.add_trace(go.Cone(x=[5,] * 3, lighting_specular=2, name="lighting.specular:2")) |
| 89 | +fig.add_trace(go.Cone(x=[6,] * 3, lighting_roughness=1, name="lighting.roughness:1")) |
| 90 | +fig.add_trace(go.Cone(x=[7,] * 3, lighting_fresnel=2, name="lighting.fresnel:2")) |
| 91 | +fig.add_trace(go.Cone(x=[8,] * 3, lightposition=dict(x=0, y=0, z=1e5), |
| 92 | + name="lighting.position x:0,y:0,z:1e5")) |
| 93 | + |
| 94 | +fig.update_traces(y=[1, 2, 3], z=[1, 1, 1], |
| 95 | + u=[1, 2, 3], v=[1, 1, 2], w=[4, 4, 1], |
| 96 | + hoverinfo="u+v+w+name", |
| 97 | + showscale=False) |
| 98 | + |
| 99 | +fig.update_layout(scene=dict(aspectmode="data", |
| 100 | + camera_eye=dict(x=0.05, y=-2.6, z=2)), |
| 101 | + margin=dict(t=0, b=0, l=0, r=0)) |
| 102 | + |
| 103 | + |
| 104 | +fig.show() |
| 105 | +``` |
| 106 | + |
| 107 | +### 3D Cone Vortex |
| 108 | + |
| 109 | +```python |
| 110 | +import plotly.graph_objects as go |
| 111 | +import pandas as pd |
| 112 | + |
| 113 | +df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv") |
| 114 | + |
| 115 | +fig = go.Figure(data = go.Cone( |
| 116 | + x=df['x'], |
| 117 | + y=df['y'], |
| 118 | + z=df['z'], |
| 119 | + u=df['u'], |
| 120 | + v=df['v'], |
| 121 | + w=df['w'], |
| 122 | + colorscale='Blues', |
| 123 | + sizemode="absolute", |
| 124 | + sizeref=40)) |
| 125 | + |
| 126 | +fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=0.8), |
| 127 | + camera_eye=dict(x=1.2, y=1.2, z=0.6))) |
| 128 | + |
| 129 | +fig.show() |
| 130 | +``` |
| 131 | + |
| 132 | +#### Reference |
| 133 | +See https://plot.ly/python/reference/ for more information and chart attribute options! |
| 134 | + |
0 commit comments