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.Tue, 19 Mar 2024 01:46:46 +0100How to specify dashed edges in SageMath?https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/
I would like to present some subgraphs of a graph. Considering that the printed version is in black and white, I would like the highlighted subgraphs to appear as red dashed lines. However, I have only seen settings for color. I am not sure how to set the dashed lines.
g=Graph([(0, 1), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 3), (1, 5), (1, 7), (1, 8), (1, 9), (1, 10),
(3, 4), (3, 5), (3, 10), (4, 5), (5, 6), (5, 7), (5, 9), (5, 10), (6, 7), (7, 8), (7, 9)])
g.plot(layout="planar",save_pos=True)
s=g.hamiltonian_cycle()
s1=s.edges(labels=False)
#print(s1)
def plot_with_highlight(G, highlight_edges):
highlight_vertices = list(set().union(*highlight_edges))
plot(G, edge_colors={'red': highlight_edges}, vertex_colors={'red': highlight_vertices}).show()
plot_with_highlight(g,s1)
![image description](/upfiles/17107541498930897.png)Mon, 18 Mar 2024 10:29:23 +0100https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/Comment by licheng for <p>I would like to present some subgraphs of a graph. Considering that the printed version is in black and white, I would like the highlighted subgraphs to appear as red dashed lines. However, I have only seen settings for color. I am not sure how to set the dashed lines.</p>
<pre><code>g=Graph([(0, 1), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 3), (1, 5), (1, 7), (1, 8), (1, 9), (1, 10),
(3, 4), (3, 5), (3, 10), (4, 5), (5, 6), (5, 7), (5, 9), (5, 10), (6, 7), (7, 8), (7, 9)])
g.plot(layout="planar",save_pos=True)
s=g.hamiltonian_cycle()
s1=s.edges(labels=False)
#print(s1)
def plot_with_highlight(G, highlight_edges):
highlight_vertices = list(set().union(*highlight_edges))
plot(G, edge_colors={'red': highlight_edges}, vertex_colors={'red': highlight_vertices}).show()
plot_with_highlight(g,s1)
</code></pre>
<p><img src="/upfiles/17107541498930897.png" alt="image description"></p>
https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/?comment=76568#post-id-76568Great, but it feels like this method isn't a modification, but rather a reconstruction of the plot.Tue, 19 Mar 2024 01:46:46 +0100https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/?comment=76568#post-id-76568Comment by Cyrille for <p>I would like to present some subgraphs of a graph. Considering that the printed version is in black and white, I would like the highlighted subgraphs to appear as red dashed lines. However, I have only seen settings for color. I am not sure how to set the dashed lines.</p>
<pre><code>g=Graph([(0, 1), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 3), (1, 5), (1, 7), (1, 8), (1, 9), (1, 10),
(3, 4), (3, 5), (3, 10), (4, 5), (5, 6), (5, 7), (5, 9), (5, 10), (6, 7), (7, 8), (7, 9)])
g.plot(layout="planar",save_pos=True)
s=g.hamiltonian_cycle()
s1=s.edges(labels=False)
#print(s1)
def plot_with_highlight(G, highlight_edges):
highlight_vertices = list(set().union(*highlight_edges))
plot(G, edge_colors={'red': highlight_edges}, vertex_colors={'red': highlight_vertices}).show()
plot_with_highlight(g,s1)
</code></pre>
<p><img src="/upfiles/17107541498930897.png" alt="image description"></p>
https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/?comment=76562#post-id-76562Have look here `https://ask.sagemath.org/question/35638/drawing-auslander-reiten-quivers-with-sage-possible/`. I rember also that you can force the vertices to a desired locations. In such a way an edge could not intersect or recover a vertexMon, 18 Mar 2024 15:14:05 +0100https://ask.sagemath.org/question/76558/how-to-specify-dashed-edges-in-sagemath/?comment=76562#post-id-76562