0

enter image description hereI have made a script for drawing a surface. The X Y are made with a regular grid. Z will be the result of the X and Y positions f(X,Y) where f is from an infinite series calculation or convergence calculation (so, no Exp Sin **2 + .. in a single formula for describing the function). It dont start in Spyder. But work in a terminal.

This command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:

An exception has occurred, use %tb to see the full traceback.

TypeError: handle_get_file_code() got an unexpected keyword argument 'save_all'

#import pdb # for debugger
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
import math as math


def agm(x0, y0): 
# return AGM https://en.wikipedia.org/wiki/Arithmetic%E2%80%93geometric_mean
    xagm_n = (x0 + y0)/2
    yagm_n = math.sqrt(x0*y0)        
    convagm = abs(xagm_n-yagm_n)        
    if (convagm < 1e-8):
        return xagm_n 
    else:
        return agm(xagm_n,yagm_n) 


def magm(half_na, half_nb, start_p=0.): 
# start_p is minimum 0; but could be choosen as the smallest of half_nx parameter
#   when it has to be initiated. perhaps it speeds the convergence.
# return MAGM
# parution http://www.ams.org/notices/201208/rtx120801094p.pdf
# author MAGM http://semjonadlaj.com/
    xmagm_n = (half_na+half_nb)/2
    ymagm_n = start_p + math.sqrt((half_na-start_p)*(half_nb-start_p))
    zmagm_n = start_p - math.sqrt((half_na-start_p)*(half_nb-start_p))
    convmagm = abs(xmagm_n-ymagm_n)
    if (convmagm < 1e-10):
        return xmagm_n
    else:
        return magm(xmagm_n,ymagm_n,zmagm_n) 


def perim(x0, y0): 
    if (x0==0.) or (y0==0.):
        Result=4.*(x0+y0)
    else:
        Result=2.*math.pi*magm(x0**2,y0**2)/agm(x0,y0)
    return Result  

#pdb.set_trace()  # start the debugger

N = 50
Wide = 10.
X = np.arange(0.,Wide,Wide/N)
Y = np.arange(0.,Wide,Wide/N)
Z=np.zeros((N, N))
for i in range(N):
    for j in range(N):
        Z[i,j]=perim((Wide/N)*i, (Wide/N)*j)
X, Y = np.meshgrid(X, Y)
# fourth dimention - colormap
# create colormap according to x-value (can use any 50x50 array)
color_dimension = Z # change to desired fourth dimension
minn, maxx = color_dimension.min(), color_dimension.max()
norm = matplotlib.colors.Normalize(minn, maxx)
m = plt.cm.ScalarMappable(norm=norm, cmap='jet')
m.set_array([])
fcolors = m.to_rgba(color_dimension)
# plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf=ax.plot_surface(X,Y,Z, rstride=1, cstride=1, facecolors=fcolors, alpha=0.5, vmin=minn, vmax=maxx, shade=False)
ax.set_xlabel('ellipse halfparam a')
ax.set_ylabel('ellipse halfparam b')
ax.set_zlabel('ellipse perim')
Windo= Wide*2*math.pi
ax.set_zlim(0, Windo)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.01f'))
fig.colorbar(surf, shrink=0.5, aspect=10)
ax.contour(X, Y, Z, 10, linewidths=1.5, cmap="autumn_r", linestyles="solid", offset=-0.1)
ax.contour(X, Y, Z, 10, linewidths=1.5, colors="k", linestyles="solid")
ax.view_init(elev=20., azim=-100.)
plt.show()
floppy_molly
  • 175
  • 1
  • 10
  • Since `save_all` and `handle_get_file_code()` don't appear in your code, I'd do what it says and "use %tb to see the full traceback". FWIW, I get an error on line 20 due to your use of `^`. Python uses `**` to raise to a power, assuming that's what you meant, and not Bitwise Exclusive Or. – jeguyer Oct 15 '21 at 17:28
  • Thank you for your nice support. It looks like that was a Spyder issue. I just have started the debugging in a terminal and found the issue you have highlighted. The code works. It show isoperimeter surface of ellipse. The color highlight the diverse isoperimeter. X and Y are the half parameter of the ellipse. Z is the perimeter value. – floppy_molly Oct 15 '21 at 19:16
  • In my jyupyterlab environment, the warning is no longer displayed after fixing the following two points. `fig,ax = plt.subplots(subplot_kw=dict(projection='3d'))` and `lw=3 `-> `linewidths=3` – r-beginners Oct 18 '21 at 08:17
  • Code modified according your linewiths advice. Works after start in a terminal (still not in Spyder). "fig,ax.." open 2 figures, its why I did not implement. – floppy_molly Oct 18 '21 at 08:41
  • Code updated. Now use of an invariant regarding a/b or b/a: achieved by using magm(a^2/sqrt(a^2+b^2),b^2/sqrt(a^2+b^2))/agm(a,b). – floppy_molly Jan 15 '23 at 20:42
  • python code updated for representing correctly the mathematic background: agm and magm are iterated functions. – floppy_molly Mar 30 '23 at 10:28

0 Answers0