Plot 2D array of (x,y,z) points in 3D space (Matplotlib)











up vote
0
down vote

favorite












I'm a beginner in Python and specially in Matplotlib. I have a 22797x3 array, built from a multiplication between two other arrays, one 22797x400 long and the other 400x3 long. In the resulted array (22797x3),each line represents a point with (x,y,z) coordinates, hence the 3 columns. How could I plot that resulted array in a 3D surface, where I can see all the 22797 points spread in 3D space? This data is for future Kmeans clustering, so I need to visualise it.



So far I've tried:



import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

#building the 22797x3 array:


#loading the first array from .txt file, 22797x400 long.
array = np.loadtxt('C:UsersScripts/final_array.txt', usecols=range(400))
array = np.float32(array)

#loading the second array from .txt file, 400x3 long.
small_vh2 = np.loadtxt('C:UsersScripts/small_vh2.txt', usecols=range(3))
small_vh2 = np.float32(small_vh2)

#multiplying and getting result array 22797x3 long:

Y = np.array(np.matmul(array,small_vh2))
#I've checked Y dimensions, it's 22797x3 long, working fine.

#now I must plot it in 3D:
fig = plt.figure()

ax = Axes3D(fig)
ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])

plt.show()


I keep getting the result shown in the image below:



https://i.stack.imgur.com/jRyHM.jpg



What I need is to get is the 22797 points, and I keep getting only 4 points plotted. Does anybody know what is wrong with the code?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm a beginner in Python and specially in Matplotlib. I have a 22797x3 array, built from a multiplication between two other arrays, one 22797x400 long and the other 400x3 long. In the resulted array (22797x3),each line represents a point with (x,y,z) coordinates, hence the 3 columns. How could I plot that resulted array in a 3D surface, where I can see all the 22797 points spread in 3D space? This data is for future Kmeans clustering, so I need to visualise it.



    So far I've tried:



    import numpy as np
    from matplotlib import pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D

    #building the 22797x3 array:


    #loading the first array from .txt file, 22797x400 long.
    array = np.loadtxt('C:UsersScripts/final_array.txt', usecols=range(400))
    array = np.float32(array)

    #loading the second array from .txt file, 400x3 long.
    small_vh2 = np.loadtxt('C:UsersScripts/small_vh2.txt', usecols=range(3))
    small_vh2 = np.float32(small_vh2)

    #multiplying and getting result array 22797x3 long:

    Y = np.array(np.matmul(array,small_vh2))
    #I've checked Y dimensions, it's 22797x3 long, working fine.

    #now I must plot it in 3D:
    fig = plt.figure()

    ax = Axes3D(fig)
    ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])

    plt.show()


    I keep getting the result shown in the image below:



    https://i.stack.imgur.com/jRyHM.jpg



    What I need is to get is the 22797 points, and I keep getting only 4 points plotted. Does anybody know what is wrong with the code?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm a beginner in Python and specially in Matplotlib. I have a 22797x3 array, built from a multiplication between two other arrays, one 22797x400 long and the other 400x3 long. In the resulted array (22797x3),each line represents a point with (x,y,z) coordinates, hence the 3 columns. How could I plot that resulted array in a 3D surface, where I can see all the 22797 points spread in 3D space? This data is for future Kmeans clustering, so I need to visualise it.



      So far I've tried:



      import numpy as np
      from matplotlib import pyplot as plt
      from mpl_toolkits.mplot3d import Axes3D

      #building the 22797x3 array:


      #loading the first array from .txt file, 22797x400 long.
      array = np.loadtxt('C:UsersScripts/final_array.txt', usecols=range(400))
      array = np.float32(array)

      #loading the second array from .txt file, 400x3 long.
      small_vh2 = np.loadtxt('C:UsersScripts/small_vh2.txt', usecols=range(3))
      small_vh2 = np.float32(small_vh2)

      #multiplying and getting result array 22797x3 long:

      Y = np.array(np.matmul(array,small_vh2))
      #I've checked Y dimensions, it's 22797x3 long, working fine.

      #now I must plot it in 3D:
      fig = plt.figure()

      ax = Axes3D(fig)
      ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])

      plt.show()


      I keep getting the result shown in the image below:



      https://i.stack.imgur.com/jRyHM.jpg



      What I need is to get is the 22797 points, and I keep getting only 4 points plotted. Does anybody know what is wrong with the code?










      share|improve this question















      I'm a beginner in Python and specially in Matplotlib. I have a 22797x3 array, built from a multiplication between two other arrays, one 22797x400 long and the other 400x3 long. In the resulted array (22797x3),each line represents a point with (x,y,z) coordinates, hence the 3 columns. How could I plot that resulted array in a 3D surface, where I can see all the 22797 points spread in 3D space? This data is for future Kmeans clustering, so I need to visualise it.



      So far I've tried:



      import numpy as np
      from matplotlib import pyplot as plt
      from mpl_toolkits.mplot3d import Axes3D

      #building the 22797x3 array:


      #loading the first array from .txt file, 22797x400 long.
      array = np.loadtxt('C:UsersScripts/final_array.txt', usecols=range(400))
      array = np.float32(array)

      #loading the second array from .txt file, 400x3 long.
      small_vh2 = np.loadtxt('C:UsersScripts/small_vh2.txt', usecols=range(3))
      small_vh2 = np.float32(small_vh2)

      #multiplying and getting result array 22797x3 long:

      Y = np.array(np.matmul(array,small_vh2))
      #I've checked Y dimensions, it's 22797x3 long, working fine.

      #now I must plot it in 3D:
      fig = plt.figure()

      ax = Axes3D(fig)
      ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])

      plt.show()


      I keep getting the result shown in the image below:



      https://i.stack.imgur.com/jRyHM.jpg



      What I need is to get is the 22797 points, and I keep getting only 4 points plotted. Does anybody know what is wrong with the code?







      numpy matplotlib mplot3d






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 at 15:01

























      asked Nov 14 at 14:31









      L'utilisatrice

      69119




      69119
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          from mpl_toolkits.mplot3d import Axes3D
          import numpy as np
          from matplotlib import pyplot as plt

          # made 2 random arrays of the same size as yours
          array = np.random.rand(22797, 400)
          small_vh2 = np.random.rand(400,3)
          Y = np.matmul(array,small_vh2)

          #now I must plot it in 3D:
          fig = plt.figure()
          ax = fig.add_subplot(111, projection='3d')

          ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
          ax.set_xlabel('X Label')
          ax.set_ylabel('Y Label')
          ax.set_zlabel('Z Label')

          plt.show()


          enter image description here






          share|improve this answer





















          • Thank you very very much!!!
            – L'utilisatrice
            Nov 14 at 21:39










          • @L'utilisatrice you are welcome.
            – anotherone
            Nov 15 at 8:53











          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',
          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%2f53302574%2fplot-2d-array-of-x-y-z-points-in-3d-space-matplotlib%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          from mpl_toolkits.mplot3d import Axes3D
          import numpy as np
          from matplotlib import pyplot as plt

          # made 2 random arrays of the same size as yours
          array = np.random.rand(22797, 400)
          small_vh2 = np.random.rand(400,3)
          Y = np.matmul(array,small_vh2)

          #now I must plot it in 3D:
          fig = plt.figure()
          ax = fig.add_subplot(111, projection='3d')

          ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
          ax.set_xlabel('X Label')
          ax.set_ylabel('Y Label')
          ax.set_zlabel('Z Label')

          plt.show()


          enter image description here






          share|improve this answer





















          • Thank you very very much!!!
            – L'utilisatrice
            Nov 14 at 21:39










          • @L'utilisatrice you are welcome.
            – anotherone
            Nov 15 at 8:53















          up vote
          0
          down vote



          accepted










          from mpl_toolkits.mplot3d import Axes3D
          import numpy as np
          from matplotlib import pyplot as plt

          # made 2 random arrays of the same size as yours
          array = np.random.rand(22797, 400)
          small_vh2 = np.random.rand(400,3)
          Y = np.matmul(array,small_vh2)

          #now I must plot it in 3D:
          fig = plt.figure()
          ax = fig.add_subplot(111, projection='3d')

          ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
          ax.set_xlabel('X Label')
          ax.set_ylabel('Y Label')
          ax.set_zlabel('Z Label')

          plt.show()


          enter image description here






          share|improve this answer





















          • Thank you very very much!!!
            – L'utilisatrice
            Nov 14 at 21:39










          • @L'utilisatrice you are welcome.
            – anotherone
            Nov 15 at 8:53













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          from mpl_toolkits.mplot3d import Axes3D
          import numpy as np
          from matplotlib import pyplot as plt

          # made 2 random arrays of the same size as yours
          array = np.random.rand(22797, 400)
          small_vh2 = np.random.rand(400,3)
          Y = np.matmul(array,small_vh2)

          #now I must plot it in 3D:
          fig = plt.figure()
          ax = fig.add_subplot(111, projection='3d')

          ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
          ax.set_xlabel('X Label')
          ax.set_ylabel('Y Label')
          ax.set_zlabel('Z Label')

          plt.show()


          enter image description here






          share|improve this answer












          from mpl_toolkits.mplot3d import Axes3D
          import numpy as np
          from matplotlib import pyplot as plt

          # made 2 random arrays of the same size as yours
          array = np.random.rand(22797, 400)
          small_vh2 = np.random.rand(400,3)
          Y = np.matmul(array,small_vh2)

          #now I must plot it in 3D:
          fig = plt.figure()
          ax = fig.add_subplot(111, projection='3d')

          ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
          ax.set_xlabel('X Label')
          ax.set_ylabel('Y Label')
          ax.set_zlabel('Z Label')

          plt.show()


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 at 20:44









          anotherone

          397317




          397317












          • Thank you very very much!!!
            – L'utilisatrice
            Nov 14 at 21:39










          • @L'utilisatrice you are welcome.
            – anotherone
            Nov 15 at 8:53


















          • Thank you very very much!!!
            – L'utilisatrice
            Nov 14 at 21:39










          • @L'utilisatrice you are welcome.
            – anotherone
            Nov 15 at 8:53
















          Thank you very very much!!!
          – L'utilisatrice
          Nov 14 at 21:39




          Thank you very very much!!!
          – L'utilisatrice
          Nov 14 at 21:39












          @L'utilisatrice you are welcome.
          – anotherone
          Nov 15 at 8:53




          @L'utilisatrice you are welcome.
          – anotherone
          Nov 15 at 8:53


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53302574%2fplot-2d-array-of-x-y-z-points-in-3d-space-matplotlib%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







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents