Reputation: 222
As stated in the question, I would like to plot a function, f(x, y)
which is represented in a vector [x, y, f(x, y)]
. So clearly the [x, y]
is the desired coordinate.
I looked up in their official page and found 3d surface plot can be done as follow:
using PlotlyJS, CSV, HTTP, DataFrames
# Read data from a csv
df = CSV.File(
HTTP.get("https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv").body
) |> DataFrame
z_data = Matrix{Float64}(df)'
(sh_0, sh_1) = size(z_data)
x = range(0, stop=1, length=sh_0)
y = range(0, stop=1, length=sh_1)
layout = Layout(
title="Mt Bruno Elevation", autosize=false,
width=500, height=500,
margin=attr(l=65, r=50, b=65, t=90)
)
plot(surface(z=z_data, x=x, y=y), layout)
Which the x
and y
parameter is just to specify the two axis domain, but not the coordinates of each element in the matrix z
.
I think these type of plot is really useful and there's no reason it cannot be done.
If there is a way to do this neatly, please educate me!
Upvotes: 0
Views: 323
Reputation: 13185
I don't use Julia (I'm a Python user), but Plotlyjs is the same on both languages. Surfaces (and contours) requires the function to be evaluated on a rectangular grid domain. For example, let x=[-2, -1, 0, 1, 2], y=[-3, -2, -1, 0, 1, 2, 3]
, the function must be evaluated on point (-2, -3), (-2, -2), (-2, -1), ..., (-1, -3), (-1, -2), (-1, -1), ..., (0, -3), (0, -2), ...
. The spacing between the grids can be non-uniform. If you have a dataset with sparse points, you can interpolate between x and y coordinates to create a grid and use it with plotly.
Upvotes: 0