Four identical subplots with different view angle





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







3















I have made the following 3D plot:



figure
subplot(2,1,1)
hold on
plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
grid on
axis equal
xlabel('x/b','Interpreter','latex')
ylabel('y/b','Interpreter','latex')
view(-45, 23);


However, I would like to create a 2x2 subplot where in each one of the 4 subplots the view angle will be different.



Instead of copying the whole code 4 times and just changing the view angle, is there some elegant way to do it?



Example of the output im trying to get:



Figure window with 4 subplots, each showing the same data but from different point of view










share|improve this question































    3















    I have made the following 3D plot:



    figure
    subplot(2,1,1)
    hold on
    plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
    plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
    plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
    plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
    plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
    plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
    grid on
    axis equal
    xlabel('x/b','Interpreter','latex')
    ylabel('y/b','Interpreter','latex')
    view(-45, 23);


    However, I would like to create a 2x2 subplot where in each one of the 4 subplots the view angle will be different.



    Instead of copying the whole code 4 times and just changing the view angle, is there some elegant way to do it?



    Example of the output im trying to get:



    Figure window with 4 subplots, each showing the same data but from different point of view










    share|improve this question



























      3












      3








      3








      I have made the following 3D plot:



      figure
      subplot(2,1,1)
      hold on
      plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
      plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
      plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
      grid on
      axis equal
      xlabel('x/b','Interpreter','latex')
      ylabel('y/b','Interpreter','latex')
      view(-45, 23);


      However, I would like to create a 2x2 subplot where in each one of the 4 subplots the view angle will be different.



      Instead of copying the whole code 4 times and just changing the view angle, is there some elegant way to do it?



      Example of the output im trying to get:



      Figure window with 4 subplots, each showing the same data but from different point of view










      share|improve this question
















      I have made the following 3D plot:



      figure
      subplot(2,1,1)
      hold on
      plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
      plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
      plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
      plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
      grid on
      axis equal
      xlabel('x/b','Interpreter','latex')
      ylabel('y/b','Interpreter','latex')
      view(-45, 23);


      However, I would like to create a 2x2 subplot where in each one of the 4 subplots the view angle will be different.



      Instead of copying the whole code 4 times and just changing the view angle, is there some elegant way to do it?



      Example of the output im trying to get:



      Figure window with 4 subplots, each showing the same data but from different point of view







      matlab plot matlab-figure






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 20:03









      Cris Luengo

      22.6k52253




      22.6k52253










      asked Nov 23 '18 at 15:00









      BenBen

      316719




      316719
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You could make use of the copyobj function.



          copyobj will allow you to replicate any graphic object you already defined. So the principle is to create your first subplot, then simply copy it 3 times and adjust the position and view of each new copy.



          To use this feature (and for many other reasons), it is good to save the handle of the graphic objects you create. This is usually done by assigning the return value of a graphic instruction to a variable. Ex:



          hp = plot(x,y) ;


          Would keep the handle of the plot object in the variable hp, so you can always use this handle to modify the line properties.



          For your specific case it would go like that:



          %% Quick mock up of a 3D triangle (you did not give any sample data)
          x = [0 ; 2 ; 1 ; 0 ] ;
          y = [3 ; 1 ; 5 ; 3 ] ;
          z = [2 ; -1 ; 4 ; 2 ] ;

          %% use dummy subplots, just to save their position on a figure
          hf = figure ;
          for k=1:4
          hs = subplot(2,2,k) ;
          axpos{k,1} = hs.OuterPosition ;
          end
          clf(hf) ; % clear all subplots, keep only "axpos" and the empty figure

          %% Generate the first subplot
          %% (use your own code for that, but don't forget to retrieve the handles of the figure and the axes)
          figure(hf) ;
          % hs(1) = subplot(2,2,1) ; % use the line below instead. It is equivalent
          % and it also set the 'hold on' mode for the axe
          hs(1) = axes('parent',hf, 'OuterPosition',axpos{1},'NextPlot','add') ;
          hp = plot3(x,y,z,'red', 'linewidth', 2) ;
          grid on
          axis equal
          xlabel('x/b','Interpreter','latex')
          ylabel('y/b','Interpreter','latex')
          view(-45, 23);

          %% Now use "copyobj" to copy the full axes object with the content and labels
          for k=2:4
          hs(k) = copyobj( hs(1) , hf ) ; % create a copy of the full subplot
          set( hs(k) , 'OuterPosition',axpos{k} ) % reposition it so it doesn't overlap the original
          end


          Then all you have to do is to change the view of each subplot according to your needs.
          This can be done by using the subplot handle as the first argument of the view instruction. For ex:



          %% adjust the view of each subplot
          view( hs(2) , 25,40)
          view( hs(3) , -25,32)
          view( hs(4) , 37,92)


          Note: If you know the view you want beforehand, you could also place the values in an array at the beginning, and set each axes view directly in the loop where you adjust their position.






          share|improve this answer





















          • 1





            Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

            – Cris Luengo
            Nov 23 '18 at 20:09











          • @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

            – Hoki
            Nov 24 '18 at 11:34



















          0














          Yes, an elegant solution would be creating a function from your code, like this.



          function [y] = changeViewAngle(pos, azimuth, elevation)
          X_LE = -1:0.01:1;
          X_TE = -1:0.01:1;
          Y_LE = -1:0.01:1;
          Z = -1:0.01:1;
          subplot(2,2,pos)
          hold on
          plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
          plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
          plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
          plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
          plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
          plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
          grid on
          axis equal
          xlabel('x/b','Interpreter','latex')
          ylabel('y/b','Interpreter','latex')
          view(azimuth, elevation)
          end


          and then saving it as a file with the same name, i.e. changeViewAngle.m



          Now create another script, main.m , which looks as below,



          figure(2);
          clear;
          clc;
          clf;

          changeViewAngle(1, -45, 23)
          changeViewAngle(2, 45, -23)
          changeViewAngle(3, 25, 90)
          changeViewAngle(4, 35, 75)


          Note: Remember to change the directory to where you saved your both files. It would be convenient if you saved them both the same folder. Otherwise, MATLAB might complain that it cannot find the function.



          Of course, you will also have to change the values for Z, X_LE, X_TE and Y_LE, according to the plot you want to make. I did not have those values, so I used some dummy values in this function. But I guess you understand how to plot 4 subplots with 4 different viewing angles, as that was the main point of your question.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448946%2ffour-identical-subplots-with-different-view-angle%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You could make use of the copyobj function.



            copyobj will allow you to replicate any graphic object you already defined. So the principle is to create your first subplot, then simply copy it 3 times and adjust the position and view of each new copy.



            To use this feature (and for many other reasons), it is good to save the handle of the graphic objects you create. This is usually done by assigning the return value of a graphic instruction to a variable. Ex:



            hp = plot(x,y) ;


            Would keep the handle of the plot object in the variable hp, so you can always use this handle to modify the line properties.



            For your specific case it would go like that:



            %% Quick mock up of a 3D triangle (you did not give any sample data)
            x = [0 ; 2 ; 1 ; 0 ] ;
            y = [3 ; 1 ; 5 ; 3 ] ;
            z = [2 ; -1 ; 4 ; 2 ] ;

            %% use dummy subplots, just to save their position on a figure
            hf = figure ;
            for k=1:4
            hs = subplot(2,2,k) ;
            axpos{k,1} = hs.OuterPosition ;
            end
            clf(hf) ; % clear all subplots, keep only "axpos" and the empty figure

            %% Generate the first subplot
            %% (use your own code for that, but don't forget to retrieve the handles of the figure and the axes)
            figure(hf) ;
            % hs(1) = subplot(2,2,1) ; % use the line below instead. It is equivalent
            % and it also set the 'hold on' mode for the axe
            hs(1) = axes('parent',hf, 'OuterPosition',axpos{1},'NextPlot','add') ;
            hp = plot3(x,y,z,'red', 'linewidth', 2) ;
            grid on
            axis equal
            xlabel('x/b','Interpreter','latex')
            ylabel('y/b','Interpreter','latex')
            view(-45, 23);

            %% Now use "copyobj" to copy the full axes object with the content and labels
            for k=2:4
            hs(k) = copyobj( hs(1) , hf ) ; % create a copy of the full subplot
            set( hs(k) , 'OuterPosition',axpos{k} ) % reposition it so it doesn't overlap the original
            end


            Then all you have to do is to change the view of each subplot according to your needs.
            This can be done by using the subplot handle as the first argument of the view instruction. For ex:



            %% adjust the view of each subplot
            view( hs(2) , 25,40)
            view( hs(3) , -25,32)
            view( hs(4) , 37,92)


            Note: If you know the view you want beforehand, you could also place the values in an array at the beginning, and set each axes view directly in the loop where you adjust their position.






            share|improve this answer





















            • 1





              Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

              – Cris Luengo
              Nov 23 '18 at 20:09











            • @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

              – Hoki
              Nov 24 '18 at 11:34
















            2














            You could make use of the copyobj function.



            copyobj will allow you to replicate any graphic object you already defined. So the principle is to create your first subplot, then simply copy it 3 times and adjust the position and view of each new copy.



            To use this feature (and for many other reasons), it is good to save the handle of the graphic objects you create. This is usually done by assigning the return value of a graphic instruction to a variable. Ex:



            hp = plot(x,y) ;


            Would keep the handle of the plot object in the variable hp, so you can always use this handle to modify the line properties.



            For your specific case it would go like that:



            %% Quick mock up of a 3D triangle (you did not give any sample data)
            x = [0 ; 2 ; 1 ; 0 ] ;
            y = [3 ; 1 ; 5 ; 3 ] ;
            z = [2 ; -1 ; 4 ; 2 ] ;

            %% use dummy subplots, just to save their position on a figure
            hf = figure ;
            for k=1:4
            hs = subplot(2,2,k) ;
            axpos{k,1} = hs.OuterPosition ;
            end
            clf(hf) ; % clear all subplots, keep only "axpos" and the empty figure

            %% Generate the first subplot
            %% (use your own code for that, but don't forget to retrieve the handles of the figure and the axes)
            figure(hf) ;
            % hs(1) = subplot(2,2,1) ; % use the line below instead. It is equivalent
            % and it also set the 'hold on' mode for the axe
            hs(1) = axes('parent',hf, 'OuterPosition',axpos{1},'NextPlot','add') ;
            hp = plot3(x,y,z,'red', 'linewidth', 2) ;
            grid on
            axis equal
            xlabel('x/b','Interpreter','latex')
            ylabel('y/b','Interpreter','latex')
            view(-45, 23);

            %% Now use "copyobj" to copy the full axes object with the content and labels
            for k=2:4
            hs(k) = copyobj( hs(1) , hf ) ; % create a copy of the full subplot
            set( hs(k) , 'OuterPosition',axpos{k} ) % reposition it so it doesn't overlap the original
            end


            Then all you have to do is to change the view of each subplot according to your needs.
            This can be done by using the subplot handle as the first argument of the view instruction. For ex:



            %% adjust the view of each subplot
            view( hs(2) , 25,40)
            view( hs(3) , -25,32)
            view( hs(4) , 37,92)


            Note: If you know the view you want beforehand, you could also place the values in an array at the beginning, and set each axes view directly in the loop where you adjust their position.






            share|improve this answer





















            • 1





              Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

              – Cris Luengo
              Nov 23 '18 at 20:09











            • @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

              – Hoki
              Nov 24 '18 at 11:34














            2












            2








            2







            You could make use of the copyobj function.



            copyobj will allow you to replicate any graphic object you already defined. So the principle is to create your first subplot, then simply copy it 3 times and adjust the position and view of each new copy.



            To use this feature (and for many other reasons), it is good to save the handle of the graphic objects you create. This is usually done by assigning the return value of a graphic instruction to a variable. Ex:



            hp = plot(x,y) ;


            Would keep the handle of the plot object in the variable hp, so you can always use this handle to modify the line properties.



            For your specific case it would go like that:



            %% Quick mock up of a 3D triangle (you did not give any sample data)
            x = [0 ; 2 ; 1 ; 0 ] ;
            y = [3 ; 1 ; 5 ; 3 ] ;
            z = [2 ; -1 ; 4 ; 2 ] ;

            %% use dummy subplots, just to save their position on a figure
            hf = figure ;
            for k=1:4
            hs = subplot(2,2,k) ;
            axpos{k,1} = hs.OuterPosition ;
            end
            clf(hf) ; % clear all subplots, keep only "axpos" and the empty figure

            %% Generate the first subplot
            %% (use your own code for that, but don't forget to retrieve the handles of the figure and the axes)
            figure(hf) ;
            % hs(1) = subplot(2,2,1) ; % use the line below instead. It is equivalent
            % and it also set the 'hold on' mode for the axe
            hs(1) = axes('parent',hf, 'OuterPosition',axpos{1},'NextPlot','add') ;
            hp = plot3(x,y,z,'red', 'linewidth', 2) ;
            grid on
            axis equal
            xlabel('x/b','Interpreter','latex')
            ylabel('y/b','Interpreter','latex')
            view(-45, 23);

            %% Now use "copyobj" to copy the full axes object with the content and labels
            for k=2:4
            hs(k) = copyobj( hs(1) , hf ) ; % create a copy of the full subplot
            set( hs(k) , 'OuterPosition',axpos{k} ) % reposition it so it doesn't overlap the original
            end


            Then all you have to do is to change the view of each subplot according to your needs.
            This can be done by using the subplot handle as the first argument of the view instruction. For ex:



            %% adjust the view of each subplot
            view( hs(2) , 25,40)
            view( hs(3) , -25,32)
            view( hs(4) , 37,92)


            Note: If you know the view you want beforehand, you could also place the values in an array at the beginning, and set each axes view directly in the loop where you adjust their position.






            share|improve this answer















            You could make use of the copyobj function.



            copyobj will allow you to replicate any graphic object you already defined. So the principle is to create your first subplot, then simply copy it 3 times and adjust the position and view of each new copy.



            To use this feature (and for many other reasons), it is good to save the handle of the graphic objects you create. This is usually done by assigning the return value of a graphic instruction to a variable. Ex:



            hp = plot(x,y) ;


            Would keep the handle of the plot object in the variable hp, so you can always use this handle to modify the line properties.



            For your specific case it would go like that:



            %% Quick mock up of a 3D triangle (you did not give any sample data)
            x = [0 ; 2 ; 1 ; 0 ] ;
            y = [3 ; 1 ; 5 ; 3 ] ;
            z = [2 ; -1 ; 4 ; 2 ] ;

            %% use dummy subplots, just to save their position on a figure
            hf = figure ;
            for k=1:4
            hs = subplot(2,2,k) ;
            axpos{k,1} = hs.OuterPosition ;
            end
            clf(hf) ; % clear all subplots, keep only "axpos" and the empty figure

            %% Generate the first subplot
            %% (use your own code for that, but don't forget to retrieve the handles of the figure and the axes)
            figure(hf) ;
            % hs(1) = subplot(2,2,1) ; % use the line below instead. It is equivalent
            % and it also set the 'hold on' mode for the axe
            hs(1) = axes('parent',hf, 'OuterPosition',axpos{1},'NextPlot','add') ;
            hp = plot3(x,y,z,'red', 'linewidth', 2) ;
            grid on
            axis equal
            xlabel('x/b','Interpreter','latex')
            ylabel('y/b','Interpreter','latex')
            view(-45, 23);

            %% Now use "copyobj" to copy the full axes object with the content and labels
            for k=2:4
            hs(k) = copyobj( hs(1) , hf ) ; % create a copy of the full subplot
            set( hs(k) , 'OuterPosition',axpos{k} ) % reposition it so it doesn't overlap the original
            end


            Then all you have to do is to change the view of each subplot according to your needs.
            This can be done by using the subplot handle as the first argument of the view instruction. For ex:



            %% adjust the view of each subplot
            view( hs(2) , 25,40)
            view( hs(3) , -25,32)
            view( hs(4) , 37,92)


            Note: If you know the view you want beforehand, you could also place the values in an array at the beginning, and set each axes view directly in the loop where you adjust their position.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 24 '18 at 11:33

























            answered Nov 23 '18 at 18:34









            HokiHoki

            9,17411536




            9,17411536








            • 1





              Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

              – Cris Luengo
              Nov 23 '18 at 20:09











            • @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

              – Hoki
              Nov 24 '18 at 11:34














            • 1





              Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

              – Cris Luengo
              Nov 23 '18 at 20:09











            • @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

              – Hoki
              Nov 24 '18 at 11:34








            1




            1





            Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

            – Cris Luengo
            Nov 23 '18 at 20:09





            Instead of figure(hf) ; hs(1) = subplot(2,2,1) you can do hs = axes('parent',hf, 'OuterPosition',axpos{1}).

            – Cris Luengo
            Nov 23 '18 at 20:09













            @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

            – Hoki
            Nov 24 '18 at 11:34





            @CrisLuengo, you're right, it is equivalent but it is more didactic on how to build these graphic objects and set their properties. I incorporated it.

            – Hoki
            Nov 24 '18 at 11:34













            0














            Yes, an elegant solution would be creating a function from your code, like this.



            function [y] = changeViewAngle(pos, azimuth, elevation)
            X_LE = -1:0.01:1;
            X_TE = -1:0.01:1;
            Y_LE = -1:0.01:1;
            Z = -1:0.01:1;
            subplot(2,2,pos)
            hold on
            plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
            plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
            plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
            plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
            plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
            plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
            grid on
            axis equal
            xlabel('x/b','Interpreter','latex')
            ylabel('y/b','Interpreter','latex')
            view(azimuth, elevation)
            end


            and then saving it as a file with the same name, i.e. changeViewAngle.m



            Now create another script, main.m , which looks as below,



            figure(2);
            clear;
            clc;
            clf;

            changeViewAngle(1, -45, 23)
            changeViewAngle(2, 45, -23)
            changeViewAngle(3, 25, 90)
            changeViewAngle(4, 35, 75)


            Note: Remember to change the directory to where you saved your both files. It would be convenient if you saved them both the same folder. Otherwise, MATLAB might complain that it cannot find the function.



            Of course, you will also have to change the values for Z, X_LE, X_TE and Y_LE, according to the plot you want to make. I did not have those values, so I used some dummy values in this function. But I guess you understand how to plot 4 subplots with 4 different viewing angles, as that was the main point of your question.






            share|improve this answer




























              0














              Yes, an elegant solution would be creating a function from your code, like this.



              function [y] = changeViewAngle(pos, azimuth, elevation)
              X_LE = -1:0.01:1;
              X_TE = -1:0.01:1;
              Y_LE = -1:0.01:1;
              Z = -1:0.01:1;
              subplot(2,2,pos)
              hold on
              plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
              plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
              plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
              plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
              plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
              plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
              grid on
              axis equal
              xlabel('x/b','Interpreter','latex')
              ylabel('y/b','Interpreter','latex')
              view(azimuth, elevation)
              end


              and then saving it as a file with the same name, i.e. changeViewAngle.m



              Now create another script, main.m , which looks as below,



              figure(2);
              clear;
              clc;
              clf;

              changeViewAngle(1, -45, 23)
              changeViewAngle(2, 45, -23)
              changeViewAngle(3, 25, 90)
              changeViewAngle(4, 35, 75)


              Note: Remember to change the directory to where you saved your both files. It would be convenient if you saved them both the same folder. Otherwise, MATLAB might complain that it cannot find the function.



              Of course, you will also have to change the values for Z, X_LE, X_TE and Y_LE, according to the plot you want to make. I did not have those values, so I used some dummy values in this function. But I guess you understand how to plot 4 subplots with 4 different viewing angles, as that was the main point of your question.






              share|improve this answer


























                0












                0








                0







                Yes, an elegant solution would be creating a function from your code, like this.



                function [y] = changeViewAngle(pos, azimuth, elevation)
                X_LE = -1:0.01:1;
                X_TE = -1:0.01:1;
                Y_LE = -1:0.01:1;
                Z = -1:0.01:1;
                subplot(2,2,pos)
                hold on
                plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
                plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
                plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
                grid on
                axis equal
                xlabel('x/b','Interpreter','latex')
                ylabel('y/b','Interpreter','latex')
                view(azimuth, elevation)
                end


                and then saving it as a file with the same name, i.e. changeViewAngle.m



                Now create another script, main.m , which looks as below,



                figure(2);
                clear;
                clc;
                clf;

                changeViewAngle(1, -45, 23)
                changeViewAngle(2, 45, -23)
                changeViewAngle(3, 25, 90)
                changeViewAngle(4, 35, 75)


                Note: Remember to change the directory to where you saved your both files. It would be convenient if you saved them both the same folder. Otherwise, MATLAB might complain that it cannot find the function.



                Of course, you will also have to change the values for Z, X_LE, X_TE and Y_LE, according to the plot you want to make. I did not have those values, so I used some dummy values in this function. But I guess you understand how to plot 4 subplots with 4 different viewing angles, as that was the main point of your question.






                share|improve this answer













                Yes, an elegant solution would be creating a function from your code, like this.



                function [y] = changeViewAngle(pos, azimuth, elevation)
                X_LE = -1:0.01:1;
                X_TE = -1:0.01:1;
                Y_LE = -1:0.01:1;
                Z = -1:0.01:1;
                subplot(2,2,pos)
                hold on
                plot3(X_LE, Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_TE, Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_LE, -Y_LE,Z, 'red', 'linewidth', 2)
                plot3(X_TE, -Y_LE,Z, 'red', 'linewidth', 2)
                plot3([X_LE(end) X_TE(end)],[Y_LE(end) Y_LE(end)],[0 0], 'red', 'linewidth', 2)
                plot3([X_LE(end) X_TE(end)],[-Y_LE(end) -Y_LE(end)],[0 0], 'red', 'linewidth', 2)
                grid on
                axis equal
                xlabel('x/b','Interpreter','latex')
                ylabel('y/b','Interpreter','latex')
                view(azimuth, elevation)
                end


                and then saving it as a file with the same name, i.e. changeViewAngle.m



                Now create another script, main.m , which looks as below,



                figure(2);
                clear;
                clc;
                clf;

                changeViewAngle(1, -45, 23)
                changeViewAngle(2, 45, -23)
                changeViewAngle(3, 25, 90)
                changeViewAngle(4, 35, 75)


                Note: Remember to change the directory to where you saved your both files. It would be convenient if you saved them both the same folder. Otherwise, MATLAB might complain that it cannot find the function.



                Of course, you will also have to change the values for Z, X_LE, X_TE and Y_LE, according to the plot you want to make. I did not have those values, so I used some dummy values in this function. But I guess you understand how to plot 4 subplots with 4 different viewing angles, as that was the main point of your question.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 18:47









                Joey MalloneJoey Mallone

                2,26361933




                2,26361933






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448946%2ffour-identical-subplots-with-different-view-angle%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()