Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I provide the full code: import ipywidgets as widgets from ipywidgets import FloatSlider, Button from IPython.display import display, clear_output from sage.all import var, sinh, cosh, sin, sqrt, cos, tan, pi, implicit_plot3d, show

x,y,z = var('x y z') t = 1# (x).function(x,y,z) cm = colormaps.gist_rainbow

Define variables

u, v, z, a = var('u v z a') x, y, z = var('x y z') coordinates = (a * sinh(v) / (cosh(v) - cos(u)), a * sin(u) / (cosh(v) - cos(u)), z) show("Bispherical coordinates") show(coordinates)

Create the sliders

EtaSlider = FloatSlider(value=0.6, min=0.1, max=1.5, step=0.1, description='u:', orientation='horizontal', continuous_update=False) ThetaSlider = FloatSlider(value=1.9, min=0.1, max=pi, step=0.1, description='v:', orientation='horizontal', continuous_update=False) PsiSlider = FloatSlider(value=6.1, min=0, max=2*pi-0.1, step=0.1, description='z:', orientation='horizontal', continuous_update=False) aSlider = FloatSlider(value=13.5, min=0.1, max=20, step=0.1, description='a:', orientation='horizontal', continuous_update=True)

Display the sliders

display(EtaSlider) display(ThetaSlider) display(PsiSlider) display(aSlider)

Create buttons

button = Button(description='Plot') button.style.button_color = 'lightgreen' display(button)

reset = Button(description='Reset values') reset.style.button_color = 'lightgreen' display(reset)

Define the update function

def update_plot(change=None): eta = float(EtaSlider.value) theta = float(ThetaSlider.value) psi = float(PsiSlider.value) a = float(aSlider.value) clear_output(wait=True)

f_1 = x**2 + y**2 + z**2 - a * (sqrt(((x**2 + y**2) / sinh(eta)**2) + z**2 / cosh(eta)**2))
f_2 = x**2 + y**2 + z**2 - a * (sqrt((-(x**2 + y**2) / sin(theta)**2) + z**2 / cos(theta)**2))
f_3 = x * tan(psi) / y

p = implicit_plot3d(f_1, (x, -30, 30), (y, -20, 20), (z, -20, 20), color='lightblue', opacity=0.9, mesh=False, frame=False, smooth=True)
q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='red', opacity=1, mesh=False, frame=False, smooth=True)
r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='lightgreen', opacity=1, mesh=False, frame=False, smooth=True)

show("Inverse prolate spheroidal coordinates")
show(coordinates)
display(EtaSlider)
display(ThetaSlider)
display(PsiSlider)
display(aSlider)
display(button)
display(reset)
show("η:%s  θ:%s  ψ:%s a:%s" % (eta, theta, psi, a))
show(p + q + r)

Define the reset function

def reset_values(sender): EtaSlider.value = 5.6 ThetaSlider.value = 1.9 PsiSlider.value = 6.1 aSlider.value = 13.5

Attach event handlers

EtaSlider.observe(update_plot, names='value') ThetaSlider.observe(update_plot, names='value') PsiSlider.observe(update_plot, names='value') aSlider.observe(update_plot, names='value') button.on_click(update_plot) reset.on_click(reset_values)

Initial plot

update_plot()

Exchange now in the implicit implicit_plot3d : color='...' by 'cmap='Reds' or any other color.

I provide the full code: import ipywidgets as widgets from ipywidgets import FloatSlider, Button from IPython.display import display, clear_output from sage.all import var, sinh, cosh, sin, sqrt, cos, tan, pi, implicit_plot3d, show

x,y,z = var('x y z') t = 1# (x).function(x,y,z) cm = colormaps.gist_rainbow

Define variables

u, v, z, a = var('u v z a') x, y, z = var('x y z') coordinates = (a * sinh(v) / (cosh(v) - cos(u)), a * sin(u) / (cosh(v) - cos(u)), z) show("Bispherical coordinates") show(coordinates)

Create the sliders

EtaSlider = FloatSlider(value=0.6, min=0.1, max=1.5, step=0.1, description='u:', orientation='horizontal', continuous_update=False) ThetaSlider = FloatSlider(value=1.9, min=0.1, max=pi, step=0.1, description='v:', orientation='horizontal', continuous_update=False) PsiSlider = FloatSlider(value=6.1, min=0, max=2*pi-0.1, step=0.1, description='z:', orientation='horizontal', continuous_update=False) aSlider = FloatSlider(value=13.5, min=0.1, max=20, step=0.1, description='a:', orientation='horizontal', continuous_update=True)

Display the sliders

display(EtaSlider) display(ThetaSlider) display(PsiSlider) display(aSlider)

Create buttons

button = Button(description='Plot') button.style.button_color = 'lightgreen' display(button)

reset = Button(description='Reset values') reset.style.button_color = 'lightgreen' display(reset)

Define the update function

def update_plot(change=None): eta = float(EtaSlider.value) theta = float(ThetaSlider.value) psi = float(PsiSlider.value) a = float(aSlider.value) clear_output(wait=True)

f_1 = x**2 + y**2 + z**2 - a * (sqrt(((x**2 + y**2) / sinh(eta)**2) + z**2 / cosh(eta)**2))
f_2 = x**2 + y**2 + z**2 - a * (sqrt((-(x**2 + y**2) / sin(theta)**2) + z**2 / cos(theta)**2))
f_3 = x * tan(psi) / y

p = implicit_plot3d(f_1, (x, -30, 30), (y, -20, 20), (z, -20, 20), color='lightblue', opacity=0.9, mesh=False, frame=False, smooth=True)
q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='red', opacity=1, mesh=False, frame=False, smooth=True)
r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='lightgreen', opacity=1, mesh=False, frame=False, smooth=True)

show("Inverse prolate spheroidal coordinates")
show(coordinates)
display(EtaSlider)
display(ThetaSlider)
display(PsiSlider)
display(aSlider)
display(button)
display(reset)
show("η:%s  θ:%s  ψ:%s a:%s" % (eta, theta, psi, a))
show(p + q + r)

Define the reset function

def reset_values(sender): EtaSlider.value = 5.6 ThetaSlider.value = 1.9 PsiSlider.value = 6.1 aSlider.value = 13.5

Attach event handlers

EtaSlider.observe(update_plot, names='value') ThetaSlider.observe(update_plot, names='value') PsiSlider.observe(update_plot, names='value') aSlider.observe(update_plot, names='value') button.on_click(update_plot) reset.on_click(reset_values)

update_plot()

Initial plot

update_plot()

Exchange Now, exchange now in the implicit implicit_plot3d : color='...' by 'cmap='Reds' or any other color., cmap='Blues', cmap='Greens' in the three functions. All colors then will be blue

I provide the full code: code:

import ipywidgets as widgets widgets

from ipywidgets import FloatSlider, Button Button

from IPython.display import display, clear_output clear_output

from sage.all import var, sinh, cosh, sin, sqrt, cos, tan, pi, implicit_plot3d, show

x,y,z = var('x y z') t = 1# (x).function(x,y,z) cm = colormaps.gist_rainbow

u, v, z, a = var('u v z a') a')

x, y, z = var('x y z') z')

coordinates = (a * sinh(v) / (cosh(v) - cos(u)), a * sin(u) / (cosh(v) - cos(u)), z) z)

show("Bispherical coordinates") coordinates")

show(coordinates)

EtaSlider = FloatSlider(value=0.6, min=0.1, max=1.5, step=0.1, description='u:', orientation='horizontal', continuous_update=False) continuous_update=False)

ThetaSlider = FloatSlider(value=1.9, min=0.1, max=pi, step=0.1, description='v:', orientation='horizontal', continuous_update=False) continuous_update=False)

PsiSlider = FloatSlider(value=6.1, min=0, max=2*pi-0.1, step=0.1, description='z:', orientation='horizontal', continuous_update=False) continuous_update=False)

aSlider = FloatSlider(value=13.5, min=0.1, max=20, step=0.1, description='a:', orientation='horizontal', continuous_update=True)

display(EtaSlider) display(ThetaSlider) display(PsiSlider) display(EtaSlider)

display(ThetaSlider)

display(PsiSlider)

display(aSlider)

button = Button(description='Plot') Button(description='Plot')

button.style.button_color = 'lightgreen' 'lightgreen'

display(button)

reset = Button(description='Reset values') values')

reset.style.button_color = 'lightgreen' 'lightgreen'

display(reset)

def update_plot(change=None): eta = float(EtaSlider.value) theta = float(ThetaSlider.value) psi = float(PsiSlider.value) a = float(aSlider.value) clear_output(wait=True)update_plot(change=None):

eta = float(EtaSlider.value)

theta = float(ThetaSlider.value)

psi = float(PsiSlider.value)

a = float(aSlider.value)

clear_output(wait=True)



f_1 = x**2 + y**2 + z**2 - a * (sqrt(((x**2 + y**2) / sinh(eta)**2) + z**2 / cosh(eta)**2))
 f_2 = x**2 + y**2 + z**2 - a * (sqrt((-(x**2 + y**2) / sin(theta)**2) + z**2 / cos(theta)**2))
 f_3 = x * tan(psi) / y
 
p = implicit_plot3d(f_1, (x, -30, 30), (y, -20, 20), (z, -20, 20), color='lightblue', opacity=0.9, mesh=False, mesh=False,

frame=False, smooth=True) smooth=True)

q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='red', opacity=1, mesh=False, frame=False, smooth=True)
frame=False,

smooth=True)

r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='lightgreen', opacity=1, mesh=False, frame=False, smooth=True)

frame=False,

smooth=True)

show("Inverse prolate spheroidal coordinates")
 show(coordinates)
 display(EtaSlider)
 display(ThetaSlider)
display(PsiSlider)
 display(aSlider)
 display(button)
 display(reset)
 show("η:%s  θ:%s  ψ:%s a:%s" % (eta, theta, psi, a))
 show(p + q + r)

def reset_values(sender): reset_values(sender):

EtaSlider.value = 5.6
  ThetaSlider.value = 1.9
  PsiSlider.value = 6.1
  aSlider.value = 13.5

13.5

EtaSlider.observe(update_plot, names='value') names='value')

ThetaSlider.observe(update_plot, names='value') names='value')

PsiSlider.observe(update_plot, names='value') names='value')

aSlider.observe(update_plot, names='value') button.on_click(update_plot) names='value')

button.on_click(update_plot)

reset.on_click(reset_values)

update_plot()

Now, exchange now in the implicit implicit_plot3d : color='...' by 'cmap='Reds' , cmap='Blues', cmap='Greens' in the the

three functions. All colors then will be blue

click to hide/show revision 4
No.4 Revision

I provide the full code:

import ipywidgets as widgets

widgets from ipywidgets import FloatSlider, Button

Button from IPython.display import display, clear_output

clear_output from sage.all import var, sinh, cosh, sin, sqrt, cos, tan, pi, implicit_plot3d, show

show x,y,z = var('x y z')

u, v, z, a = var('u v z a')

a') x, y, z = var('x y z')

z') coordinates = (a * sinh(v) / (cosh(v) - cos(u)), a * sin(u) / (cosh(v) - cos(u)), z)

z) show("Bispherical coordinates")

show(coordinates)

coordinates") show(coordinates) EtaSlider = FloatSlider(value=0.6, min=0.1, max=1.5, step=0.1, description='u:', orientation='horizontal', continuous_update=False)

continuous_update=False) ThetaSlider = FloatSlider(value=1.9, min=0.1, max=pi, step=0.1, description='v:', orientation='horizontal', continuous_update=False)

continuous_update=False) PsiSlider = FloatSlider(value=6.1, min=0, max=2*pi-0.1, step=0.1, description='z:', orientation='horizontal', continuous_update=False)

continuous_update=False) aSlider = FloatSlider(value=13.5, min=0.1, max=20, step=0.1, description='a:', orientation='horizontal', continuous_update=True)

display(EtaSlider)

display(ThetaSlider)

display(PsiSlider)

display(aSlider)

continuous_update=True) display(EtaSlider) display(ThetaSlider) display(PsiSlider) display(aSlider) button = Button(description='Plot')

Button(description='Plot') button.style.button_color = 'lightgreen'

display(button)

'lightgreen' display(button) reset = Button(description='Reset values')

values') reset.style.button_color = 'lightgreen'

display(reset)

'lightgreen' display(reset) def update_plot(change=None):

update_plot(change=None):

    eta = float(EtaSlider.value)
  theta = float(ThetaSlider.value)
  psi = float(PsiSlider.value)
  a = float(aSlider.value)

clear_output(wait=True)



    clear_output(wait=True)    

    f_1 = x**2 + y**2 + z**2 - a * (sqrt(((x**2 + y**2) / sinh(eta)**2) + z**2 / cosh(eta)**2))
  f_2 = x**2 + y**2 + z**2 - a * (sqrt((-(x**2 + y**2) / sin(theta)**2) + z**2 / cos(theta)**2))
  f_3 = x * tan(psi) / y



y    

    p = implicit_plot3d(f_1, (x, -30, 30), (y, -20, 20), (z, -20, 20), color='lightblue', opacity=0.9, mesh=False,

mesh=False, frame=False, smooth=True)

smooth=True)
    q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='red', opacity=1, mesh=False, frame=False,

smooth=True)

frame=False, 
smooth=True)
    r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), color='lightgreen', opacity=1, mesh=False, frame=False,

smooth=True)

frame=False, 
smooth=True)

    show("Inverse prolate spheroidal coordinates")
  show(coordinates)
  display(EtaSlider)
  display(ThetaSlider)
 display(PsiSlider)
  display(aSlider)
  display(button)
  display(reset)
  show("η:%s  θ:%s  ψ:%s a:%s" % (eta, theta, psi, a))
  show(p + q + r)



def reset_values(sender):

    EtaSlider.value = 5.6
    ThetaSlider.value = 1.9
    PsiSlider.value = 6.1
    aSlider.value = 13.5


EtaSlider.observe(update_plot, names='value')
ThetaSlider.observe(update_plot, names='value')
PsiSlider.observe(update_plot, names='value')
aSlider.observe(update_plot, names='value')
button.on_click(update_plot)
reset.on_click(reset_values)

update_plot()

def reset_values(sender):

EtaSlider.value = 5.6

ThetaSlider.value = 1.9

PsiSlider.value = 6.1

aSlider.value = 13.5

EtaSlider.observe(update_plot, names='value')

ThetaSlider.observe(update_plot, names='value')

PsiSlider.observe(update_plot, names='value')

aSlider.observe(update_plot, names='value')

button.on_click(update_plot)

reset.on_click(reset_values)

update_plot()

Now, exchange now in the implicit implicit_plot3d : color='...' by 'cmap='Reds' , cmap='Blues', cmap='Greens' in the

the three functions. All colors then will be blue