Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2617797

Browse files
committedSep 11, 2019
update of streamtube
1 parent 9d3c68c commit 2617797

File tree

1 file changed

+117
-52
lines changed

1 file changed

+117
-52
lines changed
 

‎unconverted/python/streamtube-plot.md renamed to ‎python/streamtube-plot.md

Lines changed: 117 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.2.3
1010
kernelspec:
11-
display_name: Python 2
11+
display_name: Python 3
1212
language: python
13-
name: python2
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
1424
plotly:
1525
description: How to make 3D streamtube plots in Python with Plotly.
1626
display_as: 3d_charts
@@ -26,37 +36,23 @@ jupyter:
2636
title: 3D Streamtube Plots | Plotly
2737
---
2838

29-
#### New to Plotly?
30-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
31-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
32-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
33-
34-
35-
#### Version Check
36-
Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.
37-
38-
```python
39-
import plotly
40-
plotly.__version__
41-
```
4239

4340
### Introduction
4441

4542

46-
In streamtube plots, attributes inlcude `x`, `y`, and `z`, which set the coorindates of the vector field, and `u`, `v`, and `w`, which sets the x, y, and z components of the vector field. Additionally, you can use `starts` to determine the streamtube's starting position. Lastly, `maxdisplayed` determines the maximum segments displayed in a streamtube.
43+
In streamtube plots, attributes inlcude `x`, `y`, and `z`, which set the coordinates of the vector field, and `u`, `v`, and `w`, which sets the x, y, and z components of the vector field. Additionally, you can use `starts` to determine the streamtube's starting position. Lastly, `maxdisplayed` determines the maximum segments displayed in a streamtube.
4744

4845

4946
### Basic Streamtube Plot
5047

5148
```python
52-
import plotly.plotly as py
53-
import plotly.graph_objs as go
49+
import plotly.graph_objects as go
5450

5551
import pandas as pd
5652

5753
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/streamtube-basic.csv')
5854

59-
data = [go.Streamtube(
55+
fig = go.Figure(data=go.Streamtube(
6056
x = df['x'],
6157
y = df['y'],
6258
z = df['z'],
@@ -67,10 +63,10 @@ data = [go.Streamtube(
6763
colorscale = 'Blues',
6864
cmin = 0,
6965
cmax = 3
70-
)
71-
]
66+
))
67+
7268

73-
layout = go.Layout(
69+
fig.update_layout(
7470
scene = dict(
7571
camera = dict(
7672
eye = dict(
@@ -82,21 +78,108 @@ layout = go.Layout(
8278
)
8379
)
8480

85-
fig = go.Figure(data=data, layout=layout)
86-
py.iplot(fig, filename='streamtube-basic')
81+
fig.show()
82+
```
83+
84+
```python
85+
import numpy as np
86+
import plotly.graph_objects as go
87+
88+
x, y, z = np.mgrid[1:4:10j, 1:4:10j, 1:4:10j]
89+
u = 0.0001 * x**2
90+
v = 0.005 * np.random.random(y.shape)
91+
w = 0.1 * z
92+
93+
sx=np.linspace(1, 4, 10, endpoint=True)
94+
sx, sy=np.meshgrid(sx, sx)
95+
sz=np.ones(sx.shape)
96+
97+
98+
fig = go.Figure(data=go.Streamtube(
99+
x=x.ravel(),
100+
y=y.ravel(),
101+
z=z.ravel(),
102+
u=u.ravel(),
103+
v=v.ravel(),
104+
w=w.ravel(),
105+
starts=dict(x=sx.flatten(),
106+
y=sy.flatten(),
107+
z=sz.flatten()),
108+
hovertext='w',
109+
sizeref=0.3
110+
))
111+
fig.show()
112+
```
113+
114+
```python
115+
import numpy as np
116+
import plotly.graph_objects as go
117+
118+
x, y, z = np.mgrid[1:2:4j, 1:2:4j, 1:2:4j]
119+
u = np.zeros_like(x)
120+
v = x.copy()
121+
w = np.zeros_like(z)
122+
123+
fig = go.Figure(data=go.Streamtube(x=x.ravel(), y=y.ravel(), z=z.ravel(),
124+
u=u.ravel(), v=v.ravel(), w=w.ravel(),
125+
hoverinfo=['x', 'y']
126+
))
127+
fig.show()
128+
```
129+
130+
```python
131+
x.ravel(), y.ravel(), z.ravel(), v.ravel()
132+
```
133+
134+
```python
135+
v.ravel()
136+
```
137+
138+
```
139+
fig.data
140+
141+
```
142+
143+
```python
144+
import numpy as np
145+
import plotly.graph_objects as go
146+
147+
x, y, z = np.mgrid[-4:4:20j, -4:4:20j, 0:4:20j]
148+
r = np.sqrt(x ** 2 + y ** 2 + z ** 2 + 0.1)
149+
#u = 0.1 * y * np.sin(r) / r
150+
u = 0.005 * np.random.random(x.shape)
151+
v = 0.005 * np.random.random(y.shape)
152+
#v = -0.1 * x * np.sin(r) / r
153+
w = 0.1 * z
154+
155+
sx=np.linspace(-4, 4, 10)
156+
sx, sy=np.meshgrid(sx, sx)
157+
sz=np.ones(sx.shape)
158+
159+
160+
fig = go.Figure(data=go.Streamtube(
161+
x=x.ravel(), y=y.ravel(), z=z.ravel(), u=u.ravel(), v=v.ravel(), w=w.ravel(),
162+
starts=dict(x=sx.flatten(),
163+
y=sy.flatten(),
164+
z=sz.flatten()),
165+
))
166+
fig.show()
167+
```
168+
169+
```python
170+
df
87171
```
88172

89173
### Starting Position and Segments
90174

91175
```python
92-
import plotly.plotly as py
93-
import plotly.graph_objs as go
176+
import plotly.graph_objects as go
94177

95178
import pandas as pd
96179

97180
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/streamtube-wind.csv').drop(['Unnamed: 0'],axis=1)
98181

99-
data = [go.Streamtube(
182+
fig = go.Figure(data=go.Streamtube(
100183
x = df['x'],
101184
y = df['y'],
102185
z = df['z'],
@@ -112,9 +195,9 @@ data = [go.Streamtube(
112195
colorscale = 'Portland',
113196
showscale = False,
114197
maxdisplayed = 3000
115-
)]
198+
))
116199

117-
layout = go.Layout(
200+
fig.update_layout(
118201
scene = dict(
119202
aspectratio = dict(
120203
x = 2,
@@ -130,31 +213,13 @@ layout = go.Layout(
130213
)
131214
)
132215

133-
fig = go.Figure(data=data, layout=layout)
134-
py.iplot(fig, filename="streamtube wind")
216+
fig.show()
135217
```
136218

137-
#### Reference
138-
See https://plot.ly/python/reference/ for more information and chart attribute options!
139-
140219
```python
141-
from IPython.display import display, HTML
142-
143-
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
144-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
145-
146-
! pip install git+https://github.com/plotly/publisher.git --upgrade
147-
import publisher
148-
publisher.publish(
149-
'streamtube.ipynb', 'python/streamtube-plot/', '3D Streamtube Plots',
150-
'How to make 3D streamtube plots in Python with Plotly.',
151-
title = '3D Streamtube Plots | Plotly',
152-
has_thumbnail='true', thumbnail='thumbnail/streamtube.jpg',
153-
language='python',
154-
display_as='3d_charts', order=21, ipynb='~notebook_demo/207',
155-
uses_plotly_offline=False)
220+
df
156221
```
157222

158-
```python
223+
#### Reference
224+
See https://plot.ly/python/reference/ for more information and chart attribute options!
159225

160-
```

0 commit comments

Comments
 (0)
Please sign in to comment.