How do I add 2 Y axis to my MATLAB Plot? - matlab

I know this question has been asked before - but none of them deal with a 3D plot with 2 Y axis. My question is a continuation of - How do I add a 2D Plot along with a surface or mesh plot in MATLAB? or this.
I have now successfully managed to add a 2D plot along with a surface plot. See image below -
Now my problem is that the range of the 2D plot is so high that the 3D plot is shrunk to look like nothing more than a plane on the ceiling. It is supposed to have variations like the figure in the question I have lined above.
How do I provide a different Y axis for the 2D plot so that the 3D plot is not shrunk like it is here.

It's possible that you can use the DataAspectRatio property to accomplish this. Taking inspiration from the example from the previous post, if we have:
z=peaks(100);
x1=linspace(0,100);
plot3(x1,0*ones(1,numel(x1)),40*sin(x1))
surface(z+40, 'edgecolor', 'none');
and then you can use
set( gca, 'dataaspectratio', [1.25 1.25 .7] )
view( [-37.5 18] )
can work in some cases to help regain some of the range on the surface plot. This method won't work, however, in very extreme cases.

Related

Matlab Polarplot() and surface color

I am a bit struggling with my polar plot. I am playing with strikes and dips, and for each pair of those, an "intensity". I'd like to plot this surface/contourf/whatever function on my polarplot. I cannot find the handle to do so. Dpp2 contains the intensity value for a given theta and rho/ strike and dip.
xTmp = (0:4:360);
yTmp = (0:22.5:90);
[strike,dip]= meshgrid(deg2rad(xTmp),deg2rad(yTmp));
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
figure('name', 'COLD');
polarplot([0 360],[0 90]);
s = surf(strike2, dip2, DPp2);
polarplot(s);
colormap
I've tried something like that, which obviously doesn't work.
cheers,
Flo
As far as I know there is no way of creating a surface plot directly in a polarplot.
One workaround is to manually create your polar axis plot. You can find an example here.
Another workaround would be to use
polarscatter to create a scatter plot (which looks simmilar in case you have a tight grid) Have a look at this.
Because you mentioned the handle: In case you want a handle to the axes have a look at polaraxes from here.
The polar scatter wasn't working, so I tried another function, which seems to work according to this page: https://fr.mathworks.com/matlabcentral/answers/95796-how-do-i-create-a-contour-plot-in-polar-coordinates
I am note quite there yet, the contour map isn't "wrapped" around my polar plot, but so far it's compiling. If anyone has an idea on how to superimpose the contour map onto the polar plot ?
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
h = polar([0 360],[0 90]);
hold on;
contourf(strike2,dip2,DPp2);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image

Draw surface of 3D cloud in matlab

I have 3D cloud of dots. I need to plot them as a surface. I tried variant with meshdrid, griddata, scatteredInterpolant,trisurf-delaunay. Nothing works. I know that this question was discussed a lot, but it seems I don't understand some important details. The code which i have now:
load('coords.mat')
figure()
subplot(1,2,1)
plot3(x,y,z,'.')
axis off
view(3)
subplot(1,2,2)
C=gray(numel(x)); % unsuccessful attempt
[~,idx]=sort(z); % to have
C=C(idx,:); % illumination
scatter3(x,y,z,50,C,'filled')
axis off
view(3)
produces the following image:
Could you help me:
1) to find a way to draw it with surface function.
and as some dots may be inside the surface (may be it is my problem)
2) How to remove 'invisible' dots?
I need solution for different cases, picture and data presents just an example.
Mat file may be downloaded here.
P.S.
In case it is important – I obtain coordinates of this dots as a rotation of random bezier curve.
UPDATE
In case data above is too big I generate another set with smaller amount of dots:
Coordinates are here.
where do you get this data from? It is represented as vectors but if you reshape it to matrices you can use the surf function. Try this code:
z=reshape(z,100,100);
y=reshape(y,100,100);
x=reshape(x,100,100);
surf(x,y,z)

Matlab - Contour plot with labeled levels over Surf plot

I would like to plot a contour or contour3 with labeled levels over a surf plot with the same data using Matlab R2015b. Finally the figure is shown from above (the view in negative z-direction) to see the result.
My problem: The labels seem to disappear in the surf area - the product lacks the intended information.
My current test-code with the best result so far:
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
surf(X,Y,Z)
shading interp
contour3(X,Y,Z,v,'k--','ShowText','on')
hold off
colormap default
caxis([-7,9])
view(0,90)
I am not yet allowed to post a picture of the result ..
Related questions in my consideration would be how to change contourf plots location on z-axis or shift the z-value of contour plot in Matlab 2014b to change the z-axis-property of a normal contour plot but they were no solution to my problem or did not work at all.
I finally understood your problem, you can solve it by doing all in 2D like so
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
contourf(x,y,z,500,'LineStyle','none');
[C,h]=contour(x,y,z,v,'k--');
clabel(C,h,'FontSize',15);
caxis([-7,9])
view(0,90)

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: