Reputation: 633
I have a function which is defined for a set of points over the surface of a cube. I know the value of the function for the coordinates. How to generate a plot which will assign a color to every point on the surface of the cube, depending on the value of the function at that point?
On 2D, I can generate colorful contour plots, but how to do something similar in 3D?
Suppose, the function which I want to plot is f(x,y,z) = x^2 + yz
.
And, the points on the cube are defined as
xvar = linspace(-1,1,20)
, yvar = linspace(-1,1,20)
, zvar = linspace(-1,1,20)
.
Upvotes: 0
Views: 537
Reputation: 8476
From:
https://octave.sourceforge.io/octave/function/scatter3.html
scatter3 (x, y, z, s, c)
Draw a 3-D scatter plot.
A marker is plotted at each point defined by the coordinates in the vectors x, y, and z.
The size of the markers is determined by s, which can be a scalar or a vector of the same length as x, y, and z. If s is not given, or is an empty matrix, then a default value of 8 points is used.
The color of the markers is determined by c, which can be a string defining a fixed color; a 3-element vector giving the red, green, and blue components of the color; a vector of the same length as x that gives a scaled index into the current colormap; or an Nx3 matrix defining the RGB color of each marker individually.
If you use colors, you can try different color profiles.
colormap(rainbow)
, colormap(jet)
etc. These color profiles assign darker color to higher values (which the default colormap does not do), which might make the plots look better.
Upvotes: 1