Ask Your Question
1

implicit_plot3d string "\n" ignored

asked 2022-04-10 22:43:09 +0100

rrogers gravatar image

updated 2022-04-11 02:44:44 +0100

I presume other plot functions have the same problem.
code clip (I will set up a real executable if it will help)

lim=2
gl=implicit_plot3d(x^2+y^2+z^2==1,(x,-lim,lim),(y,-lim,lim),(z,-lim,lim),color='purple',mesh=True)  
gl_a = ('test start'+"\n")
gl += text3d(gl_a + '\n test add'+"\n",[1,1,1] )
gl

Where gl is implicit_plot3d(...._)
I looked around and this works as expected (?)

text("Sage graphics are \n really neat because they use matplotlib!", (2,12))

Whereas this doesn't, I guess it's built in.

text3d("Sage graphics are \n really neat because they use matplotlib!", (2,12,3))

The print output is as intended, but gl plot ignores "\n"
Is there a special syntax for strings in plots?
Do I really have to add (and position) each line separately?
System: Ubuntu mate -- compiled 9.5
I wanted to provide portable and multiple HTML plot pages facilitating comparing plots, and provide enough information in the plots so that they describe themselves; more or less. So the id's don't get forgotten and lost.
Now that I think about it; there are special functions that, I think, said they would combine html "fragments" (what ever they are). Does anybody know about these programs? References are fine.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2022-04-11 23:47:05 +0100

rrogers gravatar image

updated 2022-05-10 17:20:36 +0100

Got it: just "acting out of frustration", I did the simplest thing: tested the viewers; threejs, jmol, and tachyon.
And the winner is: for the following code:
1) tachyon doesn't produce a movable object?
2) threejs: ignores "\n"
3) jmol: prints to the graph with "\n" acknowledged!

lim=2
gl=implicit_plot3d(x^2+y^2+z^2==1,(x,-lim,lim),(y,-lim,lim),(z,-lim,lim),color='purple',mesh=True) 
gl += text3d('\n test \n add'+"\n"+"test end",[3,1,1],viewer='jmol' )
gl

This means, it's not sage but some "viewer" funny business (maybe the sage interface though); BTW: I have to test some more but "jmol" is really slow.
Now, the next question is, does this carry over to a HTML save (without slow), and will such work with the complicated plots in sage manifolds.

Addendum: After working at it for a while I came across an acceptable example/alternative. Personally I would like to have a "Legend" (which I think threejs has) but this example is usable and well organized.
1) The example visualization: Kerr Black Hole with varying angular momentum, legend(?) and controls!
Note the placement manages to stay visible; whereas my experiments ended up mangling the text while rotating.
2) Source code for same: Source code
Skip down to "Plotting", it has some neat techniques and organization. It behooves you to keep control (opinion, via. "Dictionaries") to corral all the little details and keep them from running wild.

edit flag offensive delete link more
1

answered 2022-04-11 10:00:46 +0100

Emmanuel Charpentier gravatar image

The print output is as intended, but gl plot ignores "\n"

It seems that neither text nor text3d translate \n as a newline. However, this is not mentioned in their respective documentation...

Is there a special syntax for strings in plots?

It seems that text{3d} ignores control characters.

Do I really have to add (and position) each line separately?

It seems so...

I wanted to provide portable and multiple HTML plot pages facilitating comparing plots, and provide enough information in the plots so that they describe themselves; more or less. So the id's don't get forgotten and lost.

Create wrapper functions, which compute their labels, use default values if not passed.

Now that I think about it; there are special functions that, I think, said they would combine html "fragments" (what ever they are). Does anybody know about these programs? References are fine.

I doubt it :in Sage label positions are computed in the problem space ; in HTML, they are interpreted as relative to the display space....

HTH,

edit flag offensive delete link more

Comments

But the "text" in the code above does acknowledge the "\n". I can give a screenshot if you want. I am thinking about doing something with "text" and then "pasting" it some way into "text3d".l

rrogers gravatar imagerrogers ( 2022-04-11 17:09:17 +0100 )edit

I have finally followed your suggestion and found a wrapped format I am comfortable with! See section 3 above.

rrogers gravatar imagerrogers ( 2022-05-24 17:39:00 +0100 )edit
1

answered 2022-05-17 22:26:01 +0100

dan_fulea gravatar image

I also tried:

var('x,y,z')
lim = 2
gl = implicit_plot3d(x^2+y^2+z^2 == 1
                     , (x, -lim, lim), (y, -lim, lim), (z, -lim, lim)
                     , color='purple', mesh=True)
gl += text3d('test start\nHUGO\\n\ntest add', [1, 1, 1] )
gl

And the graphic object was opened with the web browser, in my case vivaldi. With Control+U i switched to the source. Searching for the HUGO inside the source, i found the lines...

var texts = [{"color": "#000000", "fontSize": 14.0, "fontFamily": ["monospace"], "fontStyle": "normal", "fontWeight": "normal", "opacity": 1.0, "text": "test start\nHUGO\\n\ntest add", "x": 1.0, "y": 1.0, "z": 1.0}];
for ( var i=0 ; i < texts.length ; i++ ) addText( texts[i] );

function addText( json ) {
    var sprite = addLabel( json.text, a[0]*json.x, a[1]*json.y, a[2]*json.z, json );
    sprite.userData = json;
}

And the js function addLabel works on the text as it randomly likes to do it.

edit flag offensive delete link more

Comments

Thanks for the directions and work (I generally try to avoid HTML coding, too transient for my taste (and the same for coding in general :) )). I followed it and will, perhaps, try to compare the "wrapper" HTML code with HUGO to see if I can trick or edit the output to acknowledge "\n" or some such.

rrogers gravatar imagerrogers ( 2022-05-24 17:44:20 +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: 2022-04-10 22:43:09 +0100

Seen: 287 times

Last updated: May 17 '22