Question about combining surf and plot3
12 views (last 30 days)
Show older comments
Hello all,
I would like to plot a 3D plot in which I plot some scattered 3D points and at the same time I would like to plot surfaces which correspond to the limits of the ranges of my three variables. I attach a .dat file which contains the variables, the variable 'parameters' contain the 3D data which to be plotted, they are 500 data points for each of the three variables. The variables p1, p2 and p3 contain the ranges of my three variables, I would like to plot the surfaces which correspond to the limits of these variables, for example for the third variable, this will do the job for the lower limit:
surf(p3(1)*ones(size(parameters,2),size(parameters,2)),'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none')
I have a problem which is that after I use the command plot3 to plot the data as follows:
figure('units','normalized','outerposition',[0 0 1 1])
surf(p3(1)*ones(size(parameters,2),size(parameters,2)),'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none')
hold on
plot3(parameters(1,:),parameters(2,:),parameters(3,:),'*r','MarkerSize',15)
hold on
plot3(parameters(1,IDEIM_mu),parameters(2,IDEIM_mu),parameters(3,IDEIM_mu),'ko','MarkerSize',20)
xlim([0.8*p1(1) 1.2*p1(2)]);
ylim([0.8*p2(1) 1.2*p2(2)]);
zlim([0.8*p3(1) 1.2*p3(2)]);
Then the first surface plot disappers. Could you please let me know how I could combine the two kind of plots ? Thanks.
2 Comments
Aquatris
on 26 Jun 2024
Edited: Aquatris
on 26 Jun 2024
My guess is your axis limits are not covering the surface plot. Comment them out and see if your surface plot is still there. If it is still there, you should adjust your axis limits
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
xDot = [8 6 1];
yDot = [2 12 16];
zDot = [.5 1 .8];
surf(X,Y,Z)
hold on
plot3(xDot,yDot,zDot,'r-*' )
hold off
Accepted Answer
Star Strider
on 26 Jun 2024
Edited: Star Strider
on 28 Jun 2024
TThe first ‘surface plot’ is just a patch plot at that goes from 0 to 500 in each (x,y) direction, at a z-value of 0.002, as can be seen when plottting it. Since xlim is set to [4E+7 6E+9] the surface plot simply never appears, since it is outside those limits.
load('Question.mat')
whos('-file','Question.mat')
Data_Presented_To_surf = p3(1)*ones(size(parameters,2),size(parameters,2))
format shortG
figure('units','normalized','outerposition',[0 0 1 1])
surf(p3(1)*ones(size(parameters,2),size(parameters,2)),'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none')
hold on
plot3(parameters(1,:),parameters(2,:),parameters(3,:),'*r','MarkerSize',15)
hold on
plot3(parameters(1,IDEIM_mu),parameters(2,IDEIM_mu),parameters(3,IDEIM_mu),'ko','MarkerSize',20)
xlim([0.8*p1(1) 1.2*p1(2)]);
xlim
ylim([0.8*p2(1) 1.2*p2(2)]);
ylim
zlim([0.8*p3(1) 1.2*p3(2)]);
zlim
EDIT — (28 Jun 2024 at 02:37)
To make the red surface aappear, just give it tthe appropriate (x,y) coorinates —
xs = linspace(min(ylim), max(xlim), 500);
ys = linspace(min(ylim), max(ylim), 500);
figure('units','normalized','outerposition',[0 0 1 1])
surf(xs, ys, p3(1)*ones(size(parameters,2),size(parameters,2)),'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none')
hold on
plot3(parameters(1,:),parameters(2,:),parameters(3,:),'*r','MarkerSize',15)
hold on
plot3(parameters(1,IDEIM_mu),parameters(2,IDEIM_mu),parameters(3,IDEIM_mu),'ko','MarkerSize',20)
xlim([0.8*p1(1) 1.2*p1(2)]);
xlim
ylim([0.8*p2(1) 1.2*p2(2)]);
ylim
zlim([0.8*p3(1) 1.2*p3(2)]);
... and there it is!
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!