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!
Note: 3D Mesh are available in version 1.10.0+
Run pip install plotly --upgrade
to update your Plotly version
import plotly
plotly.__version__
'2.0.15'
We are using data present in a separate text file. The file can be downloaded from Plotly's dataset repo.
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
pts=np.loadtxt('mesh_dataset.txt')
x,y,z=zip(*pts)
trace = go.Mesh3d(x=x,y=y,z=z,color='#FFB6C1',opacity=0.50)
py.iplot([trace])
Alphahull sets shape of mesh. If the value is -1 then Delaunay triangulation is used. If >0 then the alpha-shape algorithm is used. The default value is -1.
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
pts=np.loadtxt('mesh_dataset.txt')
x,y,z=zip(*pts)
trace = go.Mesh3d(x=x,y=y,z=z,
alphahull=5,
opacity=0.4,
color='#00FFFF')
py.iplot([trace])
data = [
go.Mesh3d(
x = [0, 1, 2, 0],
y = [0, 0, 1, 2],
z = [0, 2, 0, 1],
colorbar = go.ColorBar(
title='z'
),
colorscale = [[0, 'rgb(255, 0, 0)'],
[0.5, 'rgb(0, 255, 0)'],
[1, 'rgb(0, 0, 255)']],
intensity = [0, 0.33, 0.66, 1],
i = [0, 0, 0, 1],
j = [1, 2, 3, 2],
k = [2, 3, 1, 3],
name = 'y',
showscale = True
)
]
layout = go.Layout(
xaxis=go.XAxis(
title='x'
),
yaxis=go.YAxis(
title='y'
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='3d-mesh-tetrahedron-python')
data = [
go.Mesh3d(
x = [0, 0, 1, 1, 0, 0, 1, 1],
y = [0, 1, 1, 0, 0, 1, 1, 0],
z = [0, 0, 0, 0, 1, 1, 1, 1],
colorbar = go.ColorBar(
title='z'
),
colorscale = [[0, 'rgb(255, 0, 255)'],
[0.5, 'rgb(0, 255, 0)'],
[1, 'rgb(0, 0, 255)']],
intensity = [0, 0.142857142857143, 0.285714285714286,
0.428571428571429, 0.571428571428571,
0.714285714285714, 0.857142857142857, 1],
i = [7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],
j = [3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
k = [0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
name='y',
showscale=True
)
]
layout = go.Layout(
xaxis=go.XAxis(
title='x'
),
yaxis=go.YAxis(
title='y'
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='3d-mesh-cube-python')
See https://plotly.com/python/reference/#mesh3d for more information and chart attribute options!
from IPython.display import display, HTML
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" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
'mesh-3d.ipynb', 'python/3d-mesh/', 'Python 3D Mesh Plots | Plotly',
'How to make 3D Mesh Plots',
title= '3D Mesh Plots in Python | plotly',
name = '3D Mesh Plots',
has_thumbnail='true', thumbnail='thumbnail/3d-mesh.jpg',
language='python',
display_as='3d_charts', order=7,
ipynb= '~notebook_demo/67')
Collecting git+https://github.com/plotly/publisher.git Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-XnpO2r Building wheels for collected packages: publisher Running setup.py bdist_wheel for publisher ... done Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-VXv90N/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966 Successfully built publisher Installing collected packages: publisher Found existing installation: publisher 0.11 Uninstalling publisher-0.11: Successfully uninstalled publisher-0.11 Successfully installed publisher-0.11
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead. /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save.