Ask Your Question
0

cmap='colors' returns always blue color

asked 2024-07-11 08:01:14 +0100

pfeifhns gravatar image

updated 2024-07-11 10:51:13 +0100

FrédéricC gravatar image

Hello,

I want to plot three functions:

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, -20, 20), (y, -20, 20), (z, -20, 20), **color='blue'**, opacity=0.9, frame=False)
q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), **color='red'**, opacity=1, frame=False)
r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), **color='green'**, opacity=1, frame=False)

This works, but it doesn't look nice. So, I would like to exchange the color-definitions by cmap in this way:

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, -20, 20), (y, -20, 20), (z, -20, 20), **cmap='Blues'**, opacity=0.9, frame=False)
q = implicit_plot3d(f_2, (x, -20, 20), (y, -20, 20), (z, -20, 20), **cmap='Reds'**, opacity=1, frame=False)
r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), **cnap='Greens'**, opacity=1, frame=False)

All colors are blue!! I restarted the kernel, no change. I used the online-cell for SageMath: all is blue. Can someone show me how to use cmap correctly in implicit_plot3d?

Thank you very much

edit retag flag offensive close merge delete

Comments

1

give us values of a, theta, eta, psi for testing please

FrédéricC gravatar imageFrédéricC ( 2024-07-11 09:54:49 +0100 )edit

Like this ?

r = implicit_plot3d(f_3, (x, -20, 20), (y, -20, 20), (z, -20, 20), color=(lambda x,y,z:(z+20)/40,colormaps.Greens), opacity=1, frame=False)
FrédéricC gravatar imageFrédéricC ( 2024-07-11 09:59:03 +0100 )edit

cmap is not an allowed keyword for implicit plots. Use the syntax in the previous comment (and read the documentation).

FrédéricC gravatar imageFrédéricC ( 2024-07-11 17:01:11 +0100 )edit
FrédéricC gravatar imageFrédéricC ( 2024-07-11 18:00:18 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2024-07-11 13:11:18 +0100

pfeifhns gravatar image

updated 2024-07-11 20:41:19 +0100

FrédéricC gravatar image

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') 
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)

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(EtaSlider)
display(ThetaSlider)
display(PsiSlider)
display(aSlider)

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

reset = Button(description='Reset values')
reset.style.button_color = '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)    

    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)



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 three functions. All colors then will be blue

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2024-07-11 08:01:14 +0100

Seen: 179 times

Last updated: Jul 11