How to make a 2 dimensional colormap for scatter point plot in matlab? - matlab

I'm trying to use scatter3 to plot n points with color encoded in Matlab. Each point has four parameters, x, y, z, intensity. Now I want to build a 2-dimensional color map which determines the color of each point by two parameters separately, z, and intensity. How should I make it?

Related

Stress 3D Surface Plot in Matlab

I wrote a finite element program in Matlab which calculates the stresses of a 3D plate.
Now I would like to print these stresses but it is really hard to do for me. For each gauss point I can have the XYZ associated coordinate with its stress.
How can I do a plot like the ones I see in the FE software in Matlab? Currently what I can do is to plot a colour for the XYZ point assigning a colour range to the stresses. My result is a scatter plot.
I would like to have something like this
Thank you for your help!
Matlab has a surf(X, Y, Z, C) function that can take a color argument (C). Without the C argument, it uses the Z value to color the surface.
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
C = X.*Y;
surf(X,Y,Z,C)
The color is set using your active colormap.
If you want more control over the colors,
C can also be a MxNx3 array where the C(M, N, :) gives the RGB value of the color at the MxNth point.

Filling area of multiple contour plots that satisfies a condition in MATLAB

I have a 3D data, the x and y axis are angles and the Z axis is output. so the data is like this: [angle1 x angle2 x Z] ... I have multiple Z values at different conditions as well. Let's assume different Z values for 10 different conditions.
I want to plot a 3D contour of all the Z values overlaid on top of each other and at the same time fill the areas of each contour where Z<=-1 with a desired color ... How is that possible in MATLAB?
I found a way to overlay all the Z values on top of each other using a single color and contour command but I cannot find any way to fill the areas of Z<=-1 ... I realized that in contour command, MATLAB actually fill the whole graph with colors, so "hold on" command does not work here!
Here is an example image I want to create
Below is the example I could create but I cannot create the colored plot

"Density" plots in Matlab, but not in the sense of density of data points

I would like to plot a sort of "density map" in Matlab, but have not found the right tool yet.
I have "continuous" data with x between (x_min and x_max), and y between (y_min and y_max). At each of these pairs of points (x_i,y_i), there is associated to it a value between 0 and 1.
I would like to plot this information in a 2d graph, such that in each small square containing (x_i,y_i) the plot shades the square black for the value 0, white for the value 1, and the appropriate shade of gray for intermediate values.
Can this be done easily in Matlab?
http://www.mathworks.com/help/images/ref/mat2gray.html seems to do exactly what I need.
If the data is in a matrix A, you can just use
image(255*A); colormap gray(256); axis image;
I'm not sure what you mean by continuous (uniformly spaced?), so my answer won't make too many assumptions other than that there is a reason why you mention the coordinates (if just a regular mesh, then just image or imagesc). So, only assuming your x and y coordinates are possibly non-uniformly spaced, but at least monotonically increasing samples, try surf with view(2):
surf(X,Y,data)
view(2)
colormap gray
By default surf sets the FaceColor property with the 'flat' option:
flat — The values of CData determine the color for each face of the surface. The color data at the first vertex determine the color of the entire face.
In other words, the value will determine the shade.
Assuming your data is in data and your x and y coordinates are in x and y, here is how to do it:
imagesc(x, y, data) % to create a heat map
colormap(gray) % for gray levels
caxis([0 1]) % to set 0 to black and 1 to white
axis xy % if you want the y axis to point up
colorbar % to display the colorbar

MATLAB 3D volume visualization

I have a matrix M, 135*191*121 double and want to plot it in 3D volume by using those 121 slices. How can I do this? (I need a grayscale image)
Regards
Check out vol3d v2 , it an update to Joe Conti's vol3d function, allowing voxel colors and alpha values to be defined explicitly. In cases where voxels can be any RGB color, use:
vol3d('CData', cdata);
where cdata is an MxNxPx3 array, with RGB color along the 4th dimension. In cases where color and alpha values are highly independent, specify an MxNxP alphamatte as follows:
vol3d('CData', cdata, 'Alpha', alpha);
if you have 3 arrays, storing (x,y,z) coordinates of every point that you need to plot, then you can use function plot3
From matlab help
PLOT3 Plot lines and points in 3-D space.
PLOT3() is a three-dimensional analogue of PLOT().
PLOT3(x,y,z), where x, y and z are three vectors of the same length,
plots a line in 3-space through the points whose coordinates are the
elements of x, y and z.
PLOT3(X,Y,Z), where X, Y and Z are three matrices of the same size,
plots several lines obtained from the columns of X, Y and Z.
Various line types, plot symbols and colors may be obtained with
PLOT3(X,Y,Z,s) where s is a 1, 2 or 3 character string made from
the characters listed under the PLOT command.
PLOT3(x1,y1,z1,s1,x2,y2,z2,s2,x3,y3,z3,s3,...) combines the plots
defined by the (x,y,z,s) fourtuples, where the x's, y's and z's are
vectors or matrices and the s's are strings.
Example: A helix:
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t);
PLOT3 returns a column vector of handles to lineseries objects, one
handle per line. The X,Y,Z triples, or X,Y,Z,S quads, can be
followed by parameter/value pairs to specify additional
properties of the lines.
for 3d plots you may also want to look into surf function

matlab: how to use an array for coloring a plot

I have a set of 3d coordinates in 3 arrays X, Y, Z, and the temperature T at each point. I want to plot the points as a point cloud, such that each point will have a color according to it's temperature. Something similar to how you can specify colors in trisurf. How do I do that?
You can use SCATTER3 for that:
scatter3(X,Y,Z,12,T);