I'm trying to plot a bunch of isosurface plots together with subplot, and I want them to appear 3d and be rotatable. However, I find that when I combine subplot with isosurface the plots appear 2d and are not rotatable. Here's a MRE:
[x,y,z] = meshgrid([-3:0.25:3]);
V = x.*exp(-x.^2 -y.^2 -z.^2);
for i=1:4
subplot(2,2,i);
isosurface(x,y,z,V,1e-4);
end
How can I make this rotatable? If I plot only one isosurface, without subplot, then it's in 3d and rotatable. If I use subplot with surf, I get 4 rotatable 3d surface plots. What am I missing here?
As explained here, subplot first splits your figure into different areas and creates a 2d axis object in one of the areas.
When you then isosurface after the call to subplot, MATLAB does a 2d projection of isosurface onto the 2d axis.
surf works differently, because it forces the conversion of the axis object where it is plotted to a 3d axis object. These behaviors can be recreated as follows:
figure;
plot(1,1)
surf([1,2;1,2],[1,1;2,2],[1 1 ; 1 1]);
figure
plot(1,1)
isosurface(x,y,z,V,1e-4);
A workaround for this is to force the conversion to a 3d Axis object with view(3)(plus re-adding camlight):
[x,y,z] = meshgrid([-3:0.25:3]);
V = x.*exp(-x.^2 -y.^2 -z.^2);
figure;
for ii = 1:4
subplot(2,2,ii);
isosurface(x,y,z,V,1e-4);
view(3)
camlight;
end
Related
I currently have this plot:
The goal is to get a plot like this:
I plotted the vectors using
for idx = 1:size(starts,1)
q=quiver3(starts(idx,1), starts(idx,2), starts(idx,3), ends(idx,1), ends(idx,2), ends(idx,3), ...
'Color', RGBofStainVector(idx,:));
hold on
end
I have a 12x3 matrix with X,Y,Z points and would want to plot them in the same graph.
How can I add the different 3D points with their respective color as seen in picture 2? I tried using plot3 and scatter3 functions but had no luck.
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)
I want to plot in matlab line s=(cost,sint,0) while 0<=t<=pi
t=0:.001:pi;
x=cos(t);
y=sin(t);
z=sin(t).*0;
mesh(x,y,z)
I get an error that z must be a matrix? how can I proceed?
You want plot3, not mesh. The function mesh is used for plotting surfaces in 3D. For plotting lines in 3D you need plot3:
t=0:.001:pi;
x=cos(t);
y=sin(t);
z=sin(t).*0;
plot3(x,y,z)
Note that z can be defined more simply as z=zeros(size(t)):
t=0:.001:pi;
x=cos(t);
y=sin(t);
z=zeros(size(t));
plot3(x,y,z)
Also, since z is zero in your case, you could use plot for drawing the line in 2D, and then use view for changing to the standard 3D view:
t=0:.001:pi;
x=cos(t);
y=sin(t);
plot(x,y)
view(3)
Use plot3(x, y, z).
Could you tell me how to plot in Matlab figure such as below (smooth transition of colors)? Function countour allows only to create plot with contour lines which doesn't provide enough information to me.
You can use imagesc with the 'jet' colormap. Here's an example:
x = conv2( randn(600), fspecial('gaussian',200,20), 'valid'); %// example 2D smooth data
imagesc(x)
colormap(jet)
colorbar
grid
That is not a contour plot!
try imagesc, surf and all of their variants:
http://uk.mathworks.com/help/matlab/surface-and-mesh-plots-1.html
http://uk.mathworks.com/help/matlab/image-file-operations.html
So I have data in the form [x y z intensity] that I plot on a scatter3 figure with xyz axes. The colour of the data is used to dictate the intensity value. Problem is, using a scatter plot means the data points show up as discrete points. What I need, is a smooth shape - so I guess I need some kind of interpolation between the points?
I've tried using trisurf, but the problem with this one is that it interpolates between points that it shouldn't. So where I should have 'gaps' in my surface, it joins up the edges instead so it fills in the gaps. See the attached pics for clarification.
Does anyone have any suggestions?
The code I use is as below (the commented out scatter3 is what does the scatter plot, the rest does the trisurf):
% Read in data
dataM = csvread('3dDispersion.csv');
% scatter3(dataM(:,1), dataM(:,2), dataM(:,3), 5, dataM(:,4),'filled');
% Plot
hold on;
x = dataM(:,1);
y = dataM(:,2);
freq = dataM(:,3);
tri = delaunay(x,y);
h = trisurf(tri, x, y, freq);
% Make it pretty
% view(-45,30);
view(3);
axis vis3d;
lighting phong;
shading interp;
Use the boundary function in Matlab. This will apply a mesh similar to shrinkwrap over your points. In order to reduce the "gap closers", you will want to increase the "shrink factor".
Try K = boundary(X,Y,Z,0.9)
Where X, Y & Z are the vectors of your data points
https://www.mathworks.com/help/matlab/ref/boundary.html
You can then use trimesh or related surface plotting functions depending on how you want to display it.