3d parametric plots
New to Plotly?¶
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
Basic Parametric Plot¶
```python deletable=true editable=true import plotly.plotly as py import plotly.graph_objs as go
import numpy as np
s = np.linspace(0, 2 * np.pi, 240) t = np.linspace(0, np.pi, 240) tGrid, sGrid = np.meshgrid(s, t)
r = 2 + np.sin(7 * sGrid + 5 * tGrid) # r = 2 + sin(7s+5t) x = r * np.cos(sGrid) * np.sin(tGrid) # x = rcos(s)sin(t) y = r * np.sin(sGrid) * np.sin(tGrid) # y = rsin(s)sin(t) z = r * np.cos(tGrid) # z = r*cos(t)
surface = go.Surface(x=x, y=y, z=z) data = [surface]
layout = go.Layout( title='Parametric Plot', scene=dict( xaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), yaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), zaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ) ) )
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='Parametric_plot')
<!-- #region {"deletable": true, "editable": true} -->
#### Parametric Plot with Colorscale
<!-- #endregion -->
```python deletable=true editable=true
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
dphi, dtheta = np.pi / 250.0, np.pi / 250.0
[phi, theta] = np.mgrid[0:np.pi + dphi * 1.5:dphi, 0:2 * np.pi +
dtheta * 1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
# Applying the parametric equation..
r = (np.sin(m0 * phi) ** m1 + np.cos(m2 * phi) ** m3 +
np.sin(m4 * theta) ** m5 + np.cos(m6 * theta) ** m7)
x = r * np.sin(phi) * np.cos(theta)
y = r * np.cos(phi)
z = r * np.sin(phi) * np.sin(theta)
surface = go.Surface(x=x, y=y, z=z, colorscale='Viridis')
data = [surface]
layout = go.Layout(
title='Another Parametric Plot',
scene=dict(
xaxis=dict(
gridcolor='rgb(255, 255, 255)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(230, 230,230)'
),
yaxis=dict(
gridcolor='rgb(255, 255, 255)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(230, 230,230)'
),
zaxis=dict(
gridcolor='rgb(255, 255, 255)',
zerolinecolor='rgb(255, 255, 255)',
showbackground=True,
backgroundcolor='rgb(230, 230,230)'
)
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='parametric-plot-viridis')
Reference¶
See https://plot.ly/python/reference/#surface for more information!
```python deletable=true editable=true from IPython.display import display, HTML
display(HTML('')) display(HTML(''))
! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher publisher.publish( '3d-parametric.ipynb', 'python/3d-parametric-plots/', '3D Parametric Plots | plotly', 'How to 3D Parameteric Plots in Python', title= '3D Parametric Plots in Python | plotly', name = 'Parametric Plots', has_thumbnail='true', thumbnail='thumbnail/parametric.jpg', language='python', display_as='3d_charts', order=9, ipynb= '~notebook_demo/69')
```python deletable=true editable=true