Skip to content

Commit f2ead37

Browse files
authored
doc example with intensitymode for mesh3d (#2052)
1 parent ec09285 commit f2ead37

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

doc/python/3d-mesh.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.2'
9+
jupytext_version: 1.3.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.7.3
2424
plotly:
2525
description: How to make 3D Mesh Plots
2626
display_as: 3d_charts
@@ -127,5 +127,38 @@ fig = go.Figure(data=[
127127
fig.show()
128128
```
129129

130+
### Intensity values defined on vertices or cells
131+
132+
The `intensitymode` attribute of `go.Mesh3d` can be set to `vertex` (default mode, in which case intensity values are interpolated between values defined on vertices), or to `cell` (value of the whole cell, no interpolation). Note that the `intensity` parameter should have the same length as the number of vertices or cells, depending on the `intensitymode`.
133+
134+
Whereas the previous example used the default `intensitymode='vertex'`, we plot here the same mesh with `intensitymode='cell'`.
135+
136+
```python
137+
import plotly.graph_objects as go
138+
fig = go.Figure(data=[
139+
go.Mesh3d(
140+
# 8 vertices of a cube
141+
x=[0, 0, 1, 1, 0, 0, 1, 1],
142+
y=[0, 1, 1, 0, 0, 1, 1, 0],
143+
z=[0, 0, 0, 0, 1, 1, 1, 1],
144+
colorbar_title='z',
145+
colorscale=[[0, 'gold'],
146+
[0.5, 'mediumturquoise'],
147+
[1, 'magenta']],
148+
# Intensity of each vertex, which will be interpolated and color-coded
149+
intensity = np.linspace(0, 1, 12, endpoint=True),
150+
intensitymode='cell',
151+
# i, j and k give the vertices of triangles
152+
i = [7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],
153+
j = [3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
154+
k = [0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
155+
name='y',
156+
showscale=True
157+
)
158+
])
159+
160+
fig.show()
161+
```
162+
130163
## Reference
131164
See https://plot.ly/python/reference/#mesh3d for more information and chart attribute options!

0 commit comments

Comments
 (0)