ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 24 Feb 2021 18:44:50 +0100Can sage draw simplicial complexes?https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/ I understand it's asking a lot to draw complexes in dimensions $>3$, but for (fairly simple) 2 dimensional complexes, it seems reasonable that some plotting algorithm should exist. Even looking at, say, `simplicial_complexes.Torus()`, it doesn't seem like there's a plot or show method. The docs<sup>1</sup> don't seem to have any information either.
Since the things I'm trying to draw are fairly simple, I would be wiling to plot the $1$-skeleton (which sage can do) and then fill in the $2$-cells myself, but I'm not even sure how to go about doing that. Obviously if there is a pre-existing method or library for this, that would be the best possible solution.
Thanks in advance!
<sup>1</sup>: I don't have the karma to post links, but I'm referencing
doc.sagemath.org/html/en/reference/homology/sage/homology/simplicial_complex.htmlMon, 22 Feb 2021 23:20:51 +0100https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/Answer by John Palmieri for <p>I understand it's asking a lot to draw complexes in dimensions $>3$, but for (fairly simple) 2 dimensional complexes, it seems reasonable that some plotting algorithm should exist. Even looking at, say, <code>simplicial_complexes.Torus()</code>, it doesn't seem like there's a plot or show method. The docs<sup>1</sup> don't seem to have any information either.</p>
<p>Since the things I'm trying to draw are fairly simple, I would be wiling to plot the $1$-skeleton (which sage can do) and then fill in the $2$-cells myself, but I'm not even sure how to go about doing that. Obviously if there is a pre-existing method or library for this, that would be the best possible solution.</p>
<p>Thanks in advance!</p>
<p><sup>1</sup>: I don't have the karma to post links, but I'm referencing
doc.sagemath.org/html/en/reference/homology/sage/homology/simplicial_complex.html</p>
https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?answer=55816#post-id-55816It's a good question, and we would welcome any contributions in this direction.
Sage can only plot the 1-skeleton right now, and it does this by using the graph theory component of Sage. So if you wanted to fill in the 2-cells, you would need to access the coordinates of the vertices in the plot of the graph and then plot the corresponding triangles. I think this is the way to proceed:
T = simplicial_complexes.Torus() # for example
G = T.graph()
P = G.plot(save_pos=True)
G.get_pos() # this will return the positions of the vertices
Unfortunately the vertices are forced to be in two dimensions, and I don't see an option like `save_pos` for `G.plot3d()`. So it may be hard to get meaningful shading on the triangles.
Another option (which would be more work but might be better in the long run) would be to implement a `save_pos` option for `G.plot3d()` and then use that for plotting the triangles.Tue, 23 Feb 2021 01:47:10 +0100https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?answer=55816#post-id-55816Comment by dispo for <p>It's a good question, and we would welcome any contributions in this direction.</p>
<p>Sage can only plot the 1-skeleton right now, and it does this by using the graph theory component of Sage. So if you wanted to fill in the 2-cells, you would need to access the coordinates of the vertices in the plot of the graph and then plot the corresponding triangles. I think this is the way to proceed:</p>
<pre><code>T = simplicial_complexes.Torus() # for example
G = T.graph()
P = G.plot(save_pos=True)
G.get_pos() # this will return the positions of the vertices
</code></pre>
<p>Unfortunately the vertices are forced to be in two dimensions, and I don't see an option like <code>save_pos</code> for <code>G.plot3d()</code>. So it may be hard to get meaningful shading on the triangles.</p>
<p>Another option (which would be more work but might be better in the long run) would be to implement a <code>save_pos</code> option for <code>G.plot3d()</code> and then use that for plotting the triangles.</p>
https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?comment=55865#post-id-55865Thanks for the answer! I'll have to look into writing my own, then... If it's decently robust, maybe I'll look into submitting a pull request (or however sage handles code submission... I'll look into it once I actually have code in hand :P )Wed, 24 Feb 2021 09:13:11 +0100https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?comment=55865#post-id-55865Comment by John Palmieri for <p>It's a good question, and we would welcome any contributions in this direction.</p>
<p>Sage can only plot the 1-skeleton right now, and it does this by using the graph theory component of Sage. So if you wanted to fill in the 2-cells, you would need to access the coordinates of the vertices in the plot of the graph and then plot the corresponding triangles. I think this is the way to proceed:</p>
<pre><code>T = simplicial_complexes.Torus() # for example
G = T.graph()
P = G.plot(save_pos=True)
G.get_pos() # this will return the positions of the vertices
</code></pre>
<p>Unfortunately the vertices are forced to be in two dimensions, and I don't see an option like <code>save_pos</code> for <code>G.plot3d()</code>. So it may be hard to get meaningful shading on the triangles.</p>
<p>Another option (which would be more work but might be better in the long run) would be to implement a <code>save_pos</code> option for <code>G.plot3d()</code> and then use that for plotting the triangles.</p>
https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?comment=55891#post-id-55891That sounds great, I hope you do submit something.Wed, 24 Feb 2021 18:44:50 +0100https://ask.sagemath.org/question/55814/can-sage-draw-simplicial-complexes/?comment=55891#post-id-55891