Surface plot on top of colour image (x-y plane) - matlab

I guess, I've got an colormap issue with Matlab2013. I plot a 3d surface plot with colormap hot and I would like to have in the same plot an bitmap (8bit colour image) on the x-y plane. Plotting both separately from each other works fine but as soon as I plot them in one figure the first surface plot is only black. I guess it is because the RGB image on the x-y plane uses a different colour map. Is there an option in Matlab to plot two different type of images in the same plot?
surf(X,Y,density,'FaceColor','texturemap','Edgecolor','none')
colormap hot
...
%// define the location of the bitmap
xImage = [miX maX; miX maX]; %// The y data for the image corners
yImage = [miY miY; maY maY]; %// The x data for the image corners
zImage = [zDist zDist; zDist zDist]; %// The z data for the image corners
surf(xImage,yImage,zImage,... %// Plot the surface
'CData',RGBImage,...
'FaceColor','texturemap');
Thanks!
Durin

I think this is an issue with the relative scaling of density and zImage. I can replicate this by doing the following:
1) Plot a surf where the third input is n x m which is scaled like some real data (-0.2 to +0.2, for example). This responds to changes in colormap as you'd expect.
2) After hold on, plot another surf where the third input is n x m x 3, like a RGB image, double values scaled between 0 and 1.
This causes the first image to go "dark" (or whatever the lowest color in that particular colormap is). The issue is that they share their CLim, being in the same axis, although the RGBImage doesn't, in fact, reference the colormap.
This is "fixable" by scaling/normalising the first plot (your density values) to be between 0 and 1 (in this case) - although this quick fix is going to give you issues if you then want to add a colorbar. Alternatively, first grab the "CLim" from your axis after plotting the first surf:
trueC = get(gca,'CLim');
Then set it back after you plot the image:
set(gca,'CLim',trueC)

Related

How to place a geographical map underneath a surf plot in Matlab?

If there is an easier way to do this in general any suggestions would be appreciated.
I have imported a .nc file into Matlab and currently have a surface plot created from the interpolated matrix of data which corresponds to longitudes and latitudes. An alpha scale has been applied to add opacity and now I would like to place a map of said longs and lats beneath it so that it acts as an overlay.
here is the code used to plot where xq,yq is the mesh longitude and latitude grid and newMatrix is the interpolated version of the original matrix. Attached is the top view surf plot which I would like a map of long lat restricted x,y axis beneath (line style or topographic)
f = figure;
ax = axes('Parent',f);
h = surf(xq,yq,newMatrix,'Parent',ax);
set(h, 'edgecolor','none');
view(ax,[0,90]);
alpha color
alpha scaled
grid off
colorbar;
I'm aware of geomap but I'm not sure how it can be used in this way without causing the axis to misalign or just not be applied correctly. Before I was using a contour plot but found it easier to interpolate and plot with surf as per this post: Matlab how to make smooth contour plot?

MATLAB: imagesc() and image() display the same colormap differently

I have some data I would like to display in a picture form. In one case I want to rescale the x and y axis, which leads me to using imagesc. The issue is that the same colormap (jet) looks different in imagesc as compared to image.
Is there a way to make them the same?
I am using MATLAB R2014a.
Demonstration:
Here is how I show them:
figure; image(cancelledmap); colormap(jet); %image
figure; imagesc(y,x,cancelledmap); colormap(jet); %imagesc
And the output:
The colormap settings for both figures are somehow the same, however:
imagesc scales the color axis, whereas image does not. That's why the colors look different. If you click the colorbar button you'll see that they are on different color scales.
You can change the colorscale with caxis.
By the way, if you only want to scale the X- and Y-axes, you can use either function. Just supply your own scaled x and y vectors.

Matlab: How can I control the color of a streamtube plot?

I am currently trying to plot 3D streamtubes. I want the tubes to be colored corresponding to their respective velocity (e.g. slow = blue, fast = red).
To be more exact, I have three 3D-matrices containing the velocity in x, y and z direction. The color of the streamtubes should be sqrt(vx^2+vy^2+vz^2). When using streamtube(x,y,z,vx,vy,vz,sx,sy,sz) the tubes are colored according to their z-coordinate which is useless because it's a 3D plot anyway.
Well this wasn't easy (it ought to be a builtin option), but by modifying the CData of each tube (they are each their own graphics object), you can achieve the desired result. Here's an example
load wind
[sx,sy,sz] = meshgrid(80,20:10:50,0:5:15);
h=streamtube(x,y,z,u,v,w,sx,sy,sz);
drawnow
view(3)
axis tight
shading interp;
This gives this picture:
but then doing this:
vel=sqrt(u.^2+v.^2+w.^2); %// calculate velocities
for i=1:length(h)
%// Modify the colour data of each tube
set(h(i),'CData',interp3(x,y,z,vel,get(h(i),'XData')...
,get(h(i),'YData'),get(h(i),'ZData'),'spline'))
end
drawnow
view(3)
axis tight
shading interp;
gives this result
NOTES:
1) I don't know if this is fully correct, I don't know how to test it
2) You have to interpolate the velocity data from the points where it's known onto the vertices of the streamtubes
3) I found the spline interpolation option to work best, but the other options might work better in other cases

Need help in 3D plot using MATLAB (X,Y,Z,V)

I need to ask help in plotting a 3D volume in MATLAB. My data set includes the X, Y, Z coordinate and corresponding intensity value, V.
I was using pcolor (X,Y,V) and shading interp while i was doing the 2D images but then I got stuck when I am about to create the 3D images. I have tried scatter3, smooth3 and slice but it seems it does not fit the function I need.
My goal is to plot the 3D grid with the corresponding intensity value per coordinate and apply shading interp between these points.
I am really new in 3D plotting and I would really appreciate any help in achieving my goal. Thank you so much!
Here are some example of images that I am trying to create
(source: ndt.net)
(source: www.bam.de)
I have a solution for your first example, in which you show three cross-sections of the volume data. With this solution you can essentially plot several pcolor with different orientations, in one same 3D figure.
First, you need the data for the different slices. This is exactly what you had when you did pcolor(X,Y,V) to plot the cross section in 2D, where X, Y and V are two dimensional matrices. You will also need to create a matrix Z with the z-position of the slice (e.g. Z = zeros(size(X)) + z0). Then you use the command surface(X,Y,Z,V) to plot the cross section image in 3D, where X,Y,Z are the positions, and V is the color (value of the function).
Repeat this procedure for all the other slices, using appropriate X,Y,Z,V matrices for each slice. For slices oriented on other axes you will have to define X,Y,Z accordingly. Remember to use "hold on" after the first surface command, so that all the slices are plotted.
Example:
surface(X1,Y1,Z1,V1); shading interp; hold on
surface(X2,Y2,Z2,V2); shading interp;
surface(X3,Y3,Z3,V3); shading interp;
colormap(jet(2048)); caxis([0,3]); % color axis colormap and scaling
axis equal; xlabel('X'); ylabel('Y'); zlabel('Z') % X,Y,Z scaling and label
Result figure here:

"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