Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:03:00+00:00 2026-06-08T23:03:00+00:00

I would like to have a 3d plot with matplotlib. Data are the following:

  • 0

I would like to have a 3d plot with matplotlib.

Data are the following: I have a matrix with each row containing Y coordinates for the 3d plot. Each row first elements are the X coordinates for the 3d plot. Finally, a second matrix contains high for each point, at a X,Y position. This second matrix thus contains my Z coordinates. Both matrices are arrays of arrays with Python. I would like to know how to transform data so as to obtain:

  • a plot of each 1d signal corresponding to an X, like this (photo available online) enter image description here
  • a wireframe plot for same data, like this enter image description here

I have written an helper function for a wireframe work,

 ########  HELPER FOR PLOT 3-D

 def plot_3d(name,X,Y,Z):

     fig = plt.figure(name)
     ax = fig.gca(projection='3d')
     X = np.array(X)
     Y = np.array(Y)
     Z = np.array(Z)
     ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10)
     ax.set_xlabel('X Label')
     ax.set_ylabel('Y Label')
     plt.show()

but I dont know how to transform data X,Y,Z to make them fit requirements for matplotlib function, which want 2D lists for X, Y ,Z.

For first graph, I read help, and want to use 2d plot in 3d. Example source code gives:

x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi) / 2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z')

where z is the constant coordinate. In my case, x is the constant coordinate. I adapt with

        fig = plt.figure('2d profiles')
        ax = fig.gca(projection='3d')
        for i in range(10):
             x = pt  ## this is a scalar
             y = np.array(y)
             z = np.array(z)
             ax.plot(xs = x, y, z, xdir='x')
        plt.show()

but there is warning: non-keyword arg after keyword arg. How to fix?

Thanks and regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:03:02+00:00Added an answer on June 8, 2026 at 11:03 pm

    Regarding the display of a serie of vectors in 3D, I came with following ‘almost working’ solution:

    def visualizeSignals(self, imin, imax):
    
        times = self.time[imin:imax]
        nrows = (int)((times[(len(times)-1)] - times[0])/self.mod) + 1
    
        fig = plt.figure('2d profiles')
        ax = fig.gca(projection='3d')
        for i in range(nrows-1):
            x = self.mat1[i][0] + self.mod * i
            y = np.array(self.mat1T[i])
            z = np.array(self.mat2[i])
            ax.plot(y, z, zs = x, zdir='z')
    
        plt.show()
    

    As for 2D surface or meshgrid plot, I come through using meshgrid. Note that you can reproduce a meshgrid by yourself once you know how a meshgrid is built. For more info on meshgrid, I refer to this post.

    Here is the code (cannot use it as such since it refers to class members, but you can build your code based on 3d plot methods from matplotlib I am using)

    def visualize(self, imin, imax, typ_ = "wireframe"):
        """
        3d plot signal between imin and imax
        . typ_: type of plot, "wireframce", "surface"
        """
    
        times = self.retT[imin:imax]
        nrows = (int)((times[(len(times)-1)] - times[0])/self.mod) + 1
    
        self.modulate(imin, imax)
    
        fig = plt.figure('3d view')
        ax = fig.gca(projection='3d')
    
        x = []
        for i in range(nrows):
            x.append(self.matRetT[i][0] + self.mod * i)
    
        y = []
        for i in range(len(self.matRetT[0])):
            y.append(self.matRetT[0][i])
        y = y[:-1]
    
    
        X,Y = np.meshgrid(x,y)
    
        z = [tuple(self.matGC2D[i]) for i in range(len(self.matGC))] # matGC a matrix
    
        zzip = zip(*z)
    
        for i in range(len(z)):
            print len(z[i])
    
        if(typ_ == "wireframe"):
            ax.plot_wireframe(X,Y,zzip)
            plt.show()
        elif(typ_ == "contour"):
            cset = ax.contour(X, Y, zzip, zdir='z', offset=0)
            plt.show()
        elif(typ_ == "surf_contours"):
            surf = ax.plot_surface(X, Y, zzip, rstride=1, cstride=1, alpha=0.3)
            cset = ax.contour(X, Y, zzip, zdir='z', offset=-40)
            cset = ax.contour(X, Y, zzip, zdir='x', offset=-40)
            cset = ax.contour(X, Y, zzip, zdir='y', offset=-40)
            plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several file with the following format: lat,lon,value. I would like to plot
I have a large real 1-d data set called r. I would like plot:
I would like to have several subplots in a row in a plot. However
I would like to make a matplotlib plot having only the left and bottom
I am currently using matplotlib.pyplot to create graphs and would like to have the
I have a very simple problem regarding plot settings. I would like to have
I have a dataframe like this: block plot date data 1 1 aug 11.95171507
I have a working Python 2.6 code using matplotlib, and would like to get
I have used Matplotlib to plot lines on a figure. Now I would now
I would like to have a plot in R similar to the 2D smoothScatter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.