Question about combining surf and plot3 (2024)

28 views (last 30 days)

Show older comments

Saddam N Y on 26 Jun 2024 at 9:37

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3

Edited: Star Strider about 8 hours ago

  • Question.mat

Open in MATLAB Online

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.

1 Comment

Show -1 older commentsHide -1 older comments

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3#comment_3196211

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3#comment_3196211

Edited: Aquatris on 26 Jun 2024 at 10:45

Open in MATLAB Online

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

Question about combining surf and plot3 (3)

Sign in to comment.

Sign in to answer this question.

Answers (1)

Star Strider on 26 Jun 2024 at 12:21

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3#answer_1477451

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2132121-question-about-combining-surf-and-plot3#answer_1477451

Edited: Star Strider about 5 hours ago

Open in MATLAB Online

  • Question.mat

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)]);

Question about combining surf and plot3 (5)

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)]);

Question about combining surf and plot3 (6)

... and there it is!

.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots

Find more on Surface and Mesh Plots in Help Center and File Exchange

Tags

  • plot3
  • surf

Products

  • MATLAB

Release

R2023b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Question about combining surf and plot3 (7)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Question about combining surf and plot3 (2024)

References

Top Articles
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 6422

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.