Question about combining surf and plot3

12 visualizaciones (últimos 30 días)
Saddam N Y
Saddam N Y el 26 de Jun. de 2024
Comentada: Star Strider el 28 de Jun. de 2024
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 comentarios
Aquatris
Aquatris el 26 de Jun. de 2024
Editada: Aquatris el 26 de Jun. de 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
Saddam N Y
Saddam N Y el 28 de Jun. de 2024
Thank you very much for your answer, you are right it is a problem of the limits of my plot.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 26 de Jun. de 2024
Editada: Star Strider el 28 de Jun. de 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')
Name Size Bytes Class Attributes IDEIM_mu 1x20 160 double line1 2x1 16 matlab.graphics.chart.decoration.ConstantLine line2 2x1 16 matlab.graphics.chart.decoration.ConstantLine p1 2x1 16 double p2 2x1 16 double p3 2x1 16 double parameters 3x500 12000 double t 1x501 4008 double
Data_Presented_To_surf = p3(1)*ones(size(parameters,2),size(parameters,2))
Data_Presented_To_surf = 500x500
0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
ans = 1x2
1.0e+00 * 4e+07 6e+09
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ylim([0.8*p2(1) 1.2*p2(2)]);
ylim
ans = 1x2
0.016 0.132
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
zlim([0.8*p3(1) 1.2*p3(2)]);
zlim
ans = 1x2
0.0016 0.0132
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
ans = 1x2
1.0e+00 * 4e+07 6e+09
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ylim([0.8*p2(1) 1.2*p2(2)]);
ylim
ans = 1x2
0.016 0.132
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
zlim([0.8*p3(1) 1.2*p3(2)]);
... and there it is!
.
  2 comentarios
Saddam N Y
Saddam N Y el 28 de Jun. de 2024
Thank you very much for your answer, it makes perfect sense to include the coordinates for the surface plot.
Star Strider
Star Strider el 28 de Jun. de 2024
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by