I am trying to make a plot of an equation for a homework problem. I didn't write the code, just copied and pasted it. Shown below is the code. Does anyone know why the plot is not showing/how to fix it?
import matplotlib.pyplot as p
from mpl_toolkits.mplot3d import Axes3D
from numpy import *
from numpy import meshgrid
Nmax = 100
Niter = 600
V = zeros((Nmax, Nmax), float)
grid = ones((Nmax, Nmax))
sq3 = sqrt(3.)
y0 = -sq3 / 4.
def contour():
for j in range(0, Nmax):
V[0, j] = 1000
for i in range(0, Nmax):
y = y0 + i * 0.01
x0 = -0.5
for j in range(0, Nmax):
x = x0 + j * 0.01
if (y <= sq3 * (x + 0.25) and x < 0.) or (y < -sq3 * (x - 0.25) and x >= 0):
grid[i, j] = 0
else:
if y <= sq3 / 4. + 0.01:
V[i, j] = 0.0
for iter in range(1, Niter):
if iter % 50 == 0:
print('On iteration', iter, 'out of', Niter)
contour()
for i in range(1, Nmax - 2):
for j in range(1, Nmax - 2):
if grid[i, j] == 0.:
V[i, j] = 0.25 * (V[i + 1, j] + V[i - 1, j] + V[i, j + 1] + V[i, j - 1])
x = range(0, Nmax - 1, 2)
y = range(0, Nmax, 2)
X, Y = meshgrid(x, y)
def functz(V):
z = V[X, Y]
return z
Z = functz(V)
fig = p.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X, Y, Z, color='r')
ax.set_title('Potential within Triangle (Rotatable)')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Potential')
p.show()
I tried using savefig() but when I looked at the file it saved it was just a blank screen