Ask Your Question
1

Latex in Plot3d

asked 2023-04-20 12:54:26 +0100

Cyrille gravatar image

updated 2023-04-23 19:07:25 +0100

var('x,y,z') U(x,y)=x^.5*y^.5 levels=[0.25,.5,0.75,1,1.25,1.5,1.75,2] epsilon=0.01 p=plot3d(U(x,y),(x,0,2),(y,0,2),color='lightgreen',opacity=0.7,frame=False) for h in levels: p+=implicit_plot3d(U(x,y)==h,(x,0,2),(y,0,2),(z,h,h+epsilon),color='red') p+=implicit_plot3d(U(x,y)==h,(x,0,2),(y,0,2),(z,0,0.01),color='red')

from sage.manifolds.utilities import set_axes_labels
p+= arrow3d((0, 0, 0), (2.2, 0, 0), color='green')
p+= arrow3d((0, 0, 0), (0, 2.2, 0), color='green')
p+= arrow3d((0, 0, 0), (0, 0, 2.2), color='green')
p+= text3d(r"U(x,y) = x^.5 y^.5", (1, 1, 2.5), color=(0.5, 0, 0))
p+= set_axes_labels(p, r"x",r"y",r"z", color='lightgreen', fontweight='bold')
show(p,viewer='threejs',frame=False)

This would be nice if only the text and label have been implemented in 3D. As I could see the track has been open in 2020. Is it implemented now (https://github.com/sagemath/sage/issues/30226) ?

edit retag flag offensive close merge delete

Comments

This would be nice oif your example cared to define f... or replace it by "U".

As far as as understand it, your "question" is not a question but a wish. It would be better addressed at sage-devel or sage-support...

FWIW :

  • using floating-point exponents is usually questionable ; see this recent thread.

  • unicode_art may (feebly) help (but sqrt(x*y) hits a snage, whose orkaround is left to the reader as an exercise).

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-04-22 20:26:38 +0100 )edit

I have corrected the f. I ask my question here because I have read to ticket from 2020 ans in which a solution seems have been presented. So I was thinking that there was an error.

Cyrille gravatar imageCyrille ( 2023-04-23 19:09:07 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2023-04-22 12:59:53 +0100

achrzesz gravatar image

Waiting for a better solution in 3d graphics one can use unicode characters and for example https://www.unicodeit.net

def f(x,y):
    return math.sqrt(x*y)
P = plot3d(f, (0, 1.8), (0, 1.6), color='lightgrey',opacity=0.6)
from sage.plot.plot3d.plot3d import axes
S = P + axes(2.2, color='grey',radius=1)
po2={'fontsize':20,'color':'black'}
p= text3d(r"f(𝛼,φ) = √𝛼⋅√φ", (1,0.5,2.25),**po2)
t=text3d("𝛼",(2.3,0.0,0.0),**po2)       
t+=text3d("φ",(0.0,2.5,0.0),**po2)           
t+=text3d("θ",(0.,0.0,2.3),**po2)
S=(S+t+p).rotateZ(-pi/1.1)   
S.show(frame=False,aspect_ratio=[1,1,0.7])

or

U=lambda x,y: math.sqrt(x*y)
var("x,y,z")
z1, z2 = 0.25, 2
ni = 10
dz = (z2-z1)/ni
def col2(x,y):
    return float(0.5*dz+floor((U(x,y)-z1)/dz)/ni)
p = plot3d(U, (x,0,2), (y,0,2), color=(col2,colormaps.jet), plot_points=200)
p+= arrow3d((0, 0, 0), (2.4, 0, 0), color='red')
p+= arrow3d((0, 0, 0), (0, 2.3, 0), color='red')
p+= arrow3d((0, 0, 0), (0, 0, 3.2), color='red',radius=0.015)
po2={'fontsize':20,'color':'black'}
p+= text3d(r"U(𝛼,φ) = √𝛼⋅√φ", (0,0.5,4),**po2)
t=text3d("𝛼",(2.7,0,0),**po2)       
t+=text3d("φ",(0,2.4,0.0),**po2)            
t+=text3d("θ",(0.,0.0,3.4),**po2)
show((p+t).rotateZ(pi/1.11), aspect_ratio=[1,1,0.45],frame=False)
edit flag offensive delete link more

Comments

Thanks a lot but I have the problem with super and subscript. I have tried a lot of possible solution nothing works.

Cyrille gravatar imageCyrille ( 2023-04-23 12:12:58 +0100 )edit

Use https://www.unicodeit.net to obtain the corresponding unicode sub/superscripts

achrzesz gravatar imageachrzesz ( 2023-04-23 12:33:22 +0100 )edit

achrzesz Your solution would be great if only there was no mistakes in the conversion for instance if y^\beta gives yᵝ , x^\alpha gives x^α and x^{1/2} gives x¹^/².

Cyrille gravatar imageCyrille ( 2023-04-23 15:53:35 +0100 )edit
1

This works for me

y^b  x^a  \sqrtx

Don't expect too much, unicode is just unicode

achrzesz gravatar imageachrzesz ( 2023-04-23 18:47:47 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-04-20 12:54:26 +0100

Seen: 230 times

Last updated: Apr 23 '23