## 3D plot of x1 and x2 versus z, where z is defined as z = x1^2 + 0.1*x1 in R

Heres my code:

x1 = seq(from=0,to=1,length.out=10) x2 = seq(from=0,to=1,length.out=10) x1x2 = expand.grid(x1,x2) z = (x1)^2+0.1*(x1) z = length(length(x1x2)) x1x2z = data.frame(x1x2,z) x1x2z colnames(xyz) = c("x1=","x2","z") head(x1x2z,3) plot_ly(x1x2z,x1=~x,x2=~x2,z=~z,color="red")

I am getting the error:

No trace type specified: Based on info supplied, a 'scatter3d' trace seems appropriate. Read more about this trace type -> https://plot.ly/r/reference/#scatter3d Error: Tibble columns must have consistent lengths, only values of length one are recycled: * Length 10: Column `x` * Length 100: Columns `y`, `z`

First of all you have to tidy up in the code from above. Some naming was not correct in the example, which made the debbuging a bit trickier than necessary.

The main issue with the code was not to set the type of plot you wanted. this can be done with the type argument of plot_ly. You can use this function in the following way with the use of add trace

plot_ly(x1x2z, type="scatter3d", mode="markers") %>% add_trace( x = x1x2z$x1, y = x1x2z$x2, z = x1x2z$z, marker = list( color = 'rgb(17, 157, 255)', size = 20, line = list( color = 'rgb(231, 99, 250)', width = 2 ) ))

output image for the data in the question and the ploting function above

**2-D and 3-D Plots - MATLAB & Simulink,** Graphics functions include 2-D and 3-D plotting functions to visualize data and Until you use hold off or close the window, all plots appear in the current figure plots typically display a surface defined by a function in two variables, z = f(x,y) . If the 3D plot is compressed in one or more directions, the most lik ely problem is that the X, Y , and Z scales ha ve different ranges (e.g., X and Y go from 0 to 1000 while Z goes from 0 to 1). One solution to this problem is to scale the data to the same range via the LET

I debugged your code and used scatterplot3d instead of plot_ly.

> x1 = seq(from=0,to=1,length.out=50) # 10 seems too few > x2 = seq(from=0,to=1,length.out=50) > x1x2 = expand.grid(x1,x2) > z = (x1)^2+0.1*(x1) > #z = length(length(x1x2)) # Why do this? > x1x2z = data.frame(x1x2,z) > colnames(x1x2z) = c("x1","x2","z") > head(x1x2z,3) x1 x2 z 1 0.00000000 0 0.000000000 2 0.02040816 0 0.002457309 3 0.04081633 0 0.005747605 > library(scatterplot3d) > scatterplot3d(x1x2z, color="red")

**3-D point or line plot - MATLAB plot3,** To plot a set of coordinates connected by line segments, specify X , Y , and Z as vectors of the same length. For example, plot3(X1,Y1,Z1,'o',X2,Y2,Z2) specifies markers for the first triplet but not the for Define st and ct as vectors of sine and cosine values. Call the tiledlayout function to create a 1-by-2 tiled chart layout. how to plot y=f(x1,x2) in 3D . Learn more about plot . If one of your dimensions is discrete with no more than about 6 cases, or can reasonably be made discrete, then it can be encoded through marker shape. marker shape is not typically perceived as continuous: you can encode difference through marker shape, but people are probably not going to understand value encoded through marker shape.

The easiest way to do this is with the `rgl`

package:

library(rgl) plot3d(function(x1,x2) (x1)^2+0.1*(x1), xlim=0:1, ylim=0:1, col = "red", zlab = "z")

This produces this plot:

**[PDF] Graphs vs Level Sets Surfaces in R3,** Example: When we say “the surface z = x2 + y2,” we really mean: “The graph of the func- 2. ∣. ∣. ∣ − x2 a2. + y2 b2. = 1. } : Hyperbola. Surfaces in R3: Examples of Graphs The gradient of f : Rn → R at the point x = (x1,,xn) is the vector. To plot multiple sets of coordinates on the same set of axes, specify at least one of X, Y, or Z as a matrix and the others as vectors. example plot3( X , Y , Z , LineSpec ) creates the plot using the specified line style, marker, and color.

**I need to plot four function in matlab 4D, how can I do it?,** you mean a function with 3 real coordinate and time. Matlab can quite easily plot figures in 3D, so a 4D plot is a straightforward extension. (it is a surface in which z is a function of x and y which varies with time). I have two functions; the first is Z=f(x1,x2,x3), and W=f(x1,x2,x3,x4), where x1,x2, x3, and x4 are vectors. Z is� Three-dimensional plots typically display a surface defined by a function in two variables, z = f(x,y). To evaluate z, first create a set of (x,y) points over the domain of the function using meshgrid.

**Plotting & Graphics,** Use interactive calculators to plot and graph functions. Try 3D plots, equations, inequalities, polar and parametric plots. Specify Equations. Plot the solution set of an equation in two or three variables. surface: plot x^2 - 3y^2 - z^2 = 1. A waterfall plot is similar to a meshz plot except only mesh lines for the rows of z (x-values) are shown. The wireframe mesh is plotted using rectangles. The vertices of the rectangles [ x , y ] are typically the output of meshgrid . over a 2-D rectangular region in the x-y plane.

mesh(X1,X2,Z) In R2016b and later releases, this task does not require the use of ndgrid . Instead, you can construct the grid using implicit expansion with these commands:

##### Comments

- So what happens when you follow the advice in that apparently exceedingly informative error message? Also, the length of a data.frame is NOT the number of items or for that matter the number of rows. and
`length(length(x))`

would probably always be 1. - And where the error about "Tibble columns" is coming from is not at all clear. You have obviously not included all of your code.
- @42- "exceedingly informative...". :D :D Love it.