graph3d.py

Created by vnap0v

Created on May 02, 2025

489 Bytes

This program draws a 3D plot. The function to plot is defined in f_to_plot(x,y). The matplotlib version on the calculator only has 2D capability. This program also has to function within memory which is allocated to Python on the calculator. Tested on the calculator using software version 23.2.6.


import matplotlib.pyplot as plt
import numpy as np

def f_to_plot(x,y):
    r = np.sqrt(x**2 + y**2)
    y = np.sin(r) / r
    return y
    
Nx = 25
Ny = 20
xrange = (-9, 9)
yrange = (-9, 9)
xshift = 0.1
yshift = 0.05

x_array = np.linspace(xrange[0], xrange[1], Nx)
for i in range(Ny):
    y = yrange[0] + (yrange[1] - yrange[0]) * i / (Ny - 1)
    z = f_to_plot(x_array, y)
    dx = i * xshift
    dy = i * yshift
    plt.plot(x_array + dx, z + dy, color="red")
plt.show()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.