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 8349991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:10:41+00:00 2026-06-09T08:10:41+00:00

I want to make a 3D plot for these 100 points in X,Y and

  • 0

I want to make a 3D plot for these 100 points in X,Y and Z axes. I have generated lists that I require for all 3 axes. I assumed that this should be sufficient to plot a set of points in 3D. However I do not understand the output. I appreciate any kind of help in this regard.

################################################################
# problem : f(x) = (e**(-(y**2)))*cos(3*x)+(e**(x**2))*cos(3*y)
################################################################

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

fig = plt.figure()
ax=Axes3D(fig)
x = np.arange(-5,5,1)
y = np.arange(-5,5,1)
X = []
Y = []
Z=[]
for i in range(len(x)):
        for j in range(len(y)):
            z=(np.exp(-(y[j]**2))*np.cos(3*x[i]))+(np.exp(x[i]**2)*np.cos(3*y[j]))
        Z.append(z)
        X.append(x[i])
        Y.append(y[j])
ax.plot(X,Y,Z,'o')
plt.show()

edit/update: I am not sure if my problem is with the code itself or the way i understand 3Dplots, Should I use meshgrids to get a plot that i expect?

  • 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-09T08:10:43+00:00Added an answer on June 9, 2026 at 8:10 am

    Which version of matplotlib do you have? The documentation states that for matplotlib versions 1.0.0 and greater you should create a 3D axes as follows:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    

    rather than the ax = Axes3D(fig) used in previous versions.

    Edit Following the OPs comment it seems that is the result of the code is not as expected, rather than there being some sort of error. The following code is what I presume is intended

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    x, y = np.meshgrid(np.linspace(-5., 5., 100), np.linspace(-5., 5., 100))
    
    def zfunc(x, y):
        return np.exp(-(y**2)) * np.cos(3.*x) + np.exp(x**2) * np.cos(3.*y)
    
    z = zfunc(x, y)
    
    ax.plot_surface(x, y, z)
    
    plt.show()
    

    In the above code a two dimensional mesh is created (missing from the original post) and the function is calculated as a function of these two variables and plotted as a surface. Previously just a line of points running along x=y was being plotting.

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

Sidebar

Related Questions

I have a geom_area plot that looks like this: I want to color everything
I want to make a points plot with ggplot2 geom_point where a continuous variable
I want to make a radial stacked barchart. I have something like this: ggplot(diamonds,
This equation leads from my previous question . I want to plot dots that
I want to make a subscript for the axis label of my plot plotted
I have style sheet with a class name changebackgroundcolor i want make change in
My program generates bash scripts that call gnuplot. I don't want to have to
I use this code to make figures in Sweave <<label=fig1plot, include=FALSE >>= plot(cars) @
I want to make a scatter plot using matplotlib. If I want to use
How do I make the following plot in R? I have a file of

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.