Skip to content

Commit 3188d3a

Browse files
authored
Cone (#121)
* updated cone and quiver tutorials
1 parent 146bd06 commit 3188d3a

File tree

4 files changed

+225
-409
lines changed

4 files changed

+225
-409
lines changed

python/cone-plot.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+

python/quiver-plots.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 a quiver plot in Python. A quiver plot displays velocity
26+
vectors a arrows.
27+
display_as: scientific
28+
has_thumbnail: true
29+
ipynb: ~notebook_demo/42
30+
language: python
31+
layout: user-guide
32+
name: Quiver Plots
33+
order: 12
34+
permalink: python/quiver-plots/
35+
thumbnail: thumbnail/quiver-plot.jpg
36+
title: Python Quiver Plots | plotly
37+
---
38+
39+
#### Basic Quiver Plot
40+
41+
```python
42+
import plotly.figure_factory as ff
43+
44+
import numpy as np
45+
46+
x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
47+
u = np.cos(x)*y
48+
v = np.sin(x)*y
49+
50+
fig = ff.create_quiver(x, y, u, v)
51+
fig.show()
52+
```
53+
54+
#### Quiver Plot with Points
55+
56+
```python
57+
import plotly.figure_factory as ff
58+
import plotly.graph_objects as go
59+
60+
import numpy as np
61+
62+
x,y = np.meshgrid(np.arange(-2, 2, .2),
63+
np.arange(-2, 2, .25))
64+
z = x*np.exp(-x**2 - y**2)
65+
v, u = np.gradient(z, .2, .2)
66+
67+
# Create quiver figure
68+
fig = ff.create_quiver(x, y, u, v,
69+
scale=.25,
70+
arrow_scale=.4,
71+
name='quiver',
72+
line_width=1)
73+
74+
# Add points to figure
75+
fig.add_trace(go.Scatter(x=[-.7, .75], y=[0,0],
76+
mode='markers',
77+
marker_size=12,
78+
name='points'))
79+
80+
fig.show()
81+
```
82+
83+
#### See also
84+
85+
[Cone plots](./cone-plot) for the 3D equivalent of quiver plots.
86+
87+
#### Reference
88+
89+
```python
90+
help(ff.create_quiver)
91+
```

0 commit comments

Comments
 (0)