Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4941b7

Browse files
committed
added 3d surface example
1 parent 5a05be1 commit d4941b7

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

doc/python/3d-surface-plots.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ 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-surface plots in Python
2626
display_as: 3d_charts
2727
language: python
2828
layout: base
2929
name: 3D Surface Plots
30-
order: 3
30+
order: 6
3131
page_type: example_index
3232
permalink: python/3d-surface-plots/
3333
thumbnail: thumbnail/3d-surface.jpg
@@ -52,6 +52,31 @@ fig.update_layout(title='Mt Bruno Elevation', autosize=False,
5252
fig.show()
5353
```
5454

55+
### Passing x and y data to 3D Surface Plot
56+
57+
If you do not specify `x` and `y` coordinates, integer indices are used for the `x` and `y` axis. You can also pass `x` and `y` values to `go.Surface`.
58+
59+
```python
60+
import plotly.graph_objects as go
61+
62+
import pandas as pd
63+
import numpy as np
64+
65+
# Read data from a csv
66+
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')
67+
z = z_data.values
68+
sh_0, sh_1 = z.shape
69+
x, y = np.linspace(0, 1, sh_0), np.linspace(0, 1, sh_1)
70+
71+
fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)])
72+
73+
fig.update_layout(title='Mt Bruno Elevation', autosize=False,
74+
width=500, height=500,
75+
margin=dict(l=65, r=50, b=65, t=90))
76+
77+
fig.show()
78+
```
79+
5580
#### Surface Plot With Contours
5681

5782

@@ -76,35 +101,7 @@ fig.update_layout(title='Mt Bruno Elevation', autosize=False,
76101

77102
fig.show()
78103
```
79-
#### Configure Surface Contour Levels
80-
This example shows how to slice the surface graph on the desired position for each of x, y and z axis. [contours.x.start](https://plot.ly/python/reference/#surface-contours-x-start) sets the starting contour level value, `end` sets the end of it, and `size` sets the step between each contour level.
81-
82-
```python
83-
import plotly.graph_objects as go
84104

85-
fig = go.Figure(go.Surface(
86-
contours = {
87-
"x": {"show": True, "start": 1.5, "end": 2, "size": 0.04, "color":"white"},
88-
"z": {"show": True, "start": 0.5, "end": 0.8, "size": 0.05}
89-
},
90-
x = [1,2,3,4,5],
91-
y = [1,2,3,4,5],
92-
z = [
93-
[0, 1, 0, 1, 0],
94-
[1, 0, 1, 0, 1],
95-
[0, 1, 0, 1, 0],
96-
[1, 0, 1, 0, 1],
97-
[0, 1, 0, 1, 0]
98-
]))
99-
fig.update_layout(
100-
scene = {
101-
"xaxis": {"nticks": 20},
102-
"zaxis": {"nticks": 4},
103-
'camera_eye': {"x": 0, "y": -1, "z": 0.5},
104-
"aspectratio": {"x": 1, "y": 1, "z": 0.2}
105-
})
106-
fig.show()
107-
```
108105
#### Multiple 3D Surface Plots
109106

110107
```python

0 commit comments

Comments
 (0)