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

  • Home
  • SEARCH
  • 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 7030173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:38:06+00:00 2026-05-28T00:38:06+00:00

I have a z function that accepts x and y parameters and returns a

  • 0

I have a z function that accepts x and y parameters and returns a z output. I want to plot this in 3d and set the scales. How can I do this easily? I’ve spent way too much time looking through the documentation and not once do I see a way to do this.

  • 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-05-28T00:38:06+00:00Added an answer on May 28, 2026 at 12:38 am

    The plotting style depends on your data: are you trying to plot a 3D curve (line), a surface, or a scatter of points?

    In the first example below I’ve just used a simple grid of evenly spaced points in the x-y plane for the domain. Generally, you first create a domain of xs and ys, and then calculate the zs from that.

    This code should give you a working example to start playing with:

    import numpy as np
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import random
    
    def fun(x, y):
        return x + y
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    n = 10
    xs = [i for i in range(n) for _ in range(n)]
    ys = list(range(n)) * n
    zs = [fun(x, y) for x,y in zip(xs,ys)]
    
    ax.scatter(xs, ys, zs)
    
    ax.set_xlabel('X Label')
    ax.set_ylabel('Y Label')
    ax.set_zlabel('Z Label')
    
    plt.show()
    

    scatter


    For surfaces it’s a bit different, you pass in a grid for the domain in 2d arrays. Here’s a smooth surface example:

    import numpy as np
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import random
    
    def fun(x, y):
        return x**2 + y
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    x = y = np.arange(-3.0, 3.0, 0.05)
    X, Y = np.meshgrid(x, y)
    zs = np.array([fun(x,y) for x,y in zip(np.ravel(X), np.ravel(Y))])
    Z = zs.reshape(X.shape)
    
    ax.plot_surface(X, Y, Z)
    
    ax.set_xlabel('X Label')
    ax.set_ylabel('Y Label')
    ax.set_zlabel('Z Label')
    
    plt.show()
    

    surface

    For many more examples, check out the mplot3d tutorial in the docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that accepts one parameter and returns a table/resultset. I want
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function that accepts a variable number of parameters: foo (Class... types);
I have a function that accepts a char* as one of its parameters. I
Does Actionscript have a built-in function that accepts a number and can return a
Please suppose I have a function that accepts a pointer as a parameter. This
I have a function that accepts a generic parameter T that is of type
I have a function that accepts an anonymous function as an argument and sets
I have a function that accepts a class (not an instance) and, depending on
I have a javascript function that accepts a number and performs a mathematical operation

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.