1

I am using the sample code to make surface plots in python3 using plotly.

The sample code from plotly is:

import plotly.plotly as py
import plotly.graph_objs as go

import pandas as pd

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

data = [
    go.Surface(
        z=z_data.as_matrix()
    )
]
layout = go.Layout(
    title='Mt Bruno Elevation',
    autosize=False,
    width=500,
    height=500,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    )
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='elevations-3d-surface')

The data is a 25x25 table of values. The resulting plot is a typical x,y,z surface plot. However, nowhere did we pick which column we wanted to be x, y and z. So how is this defined in plotly?

1 Answer 1

0

z is actually the grid matrix for axis Z created from X and Y axis values.

Lets say,

x = [1, 2, 3, 4, 5]
y = [11, 12, 13, 14, 15]
# Let z = x + y, then the values of z would be
z = [[12, 13, 14, 15, 16],
     [13, 14, 15, 16, 17],
     [14, 15, 16, 17, 18],
     [15, 16, 17, 18, 19],
     [16, 17, 18, 19, 20],
    ]

Now you can draw the surface graph

data = [
    go.Surface(
        x=x,
        y=y,
        z=z
    )
]

layout = go.Layout(
    title='Sample Graph',
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='sample-graph')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.