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.Sun, 01 Feb 2015 00:42:31 +0100how do I set label of multiedges graphhttps://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/ Hello,
Let me consider a graph that I often need to use: the graph with one vertex and three loops.
sage: G = DiGraph([(0,0,'a'), (0,0,'b'), (0,0,'c')])
Is there a way to change the labels after the creation? Because
sage: G.set_edge_label(0,0,'d')
Traceback (most recent call last):
...
RuntimeError: Cannot set edge label, since there are multiple edges from 0 to 0.
VincentSat, 31 Jan 2015 21:01:13 +0100https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/Answer by tmonteil for <p>Hello,</p>
<p>Let me consider a graph that I often need to use: the graph with one vertex and three loops.</p>
<pre><code>sage: G = DiGraph([(0,0,'a'), (0,0,'b'), (0,0,'c')])
</code></pre>
<p>Is there a way to change the labels after the creation? Because</p>
<pre><code>sage: G.set_edge_label(0,0,'d')
Traceback (most recent call last):
...
RuntimeError: Cannot set edge label, since there are multiple edges from 0 to 0.
</code></pre>
<p>Vincent</p>
https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?answer=25660#post-id-25660Of course you would have to specify which label will be replaced by `'d'`. I did not found such a method in Sage (and unfortunately the `.set_edge_label()` method does not offer the possibility to specify which edge you would like to relabel), but you can always fallback to:
sage: G.edges()
[(0, 0, 'a'), (0, 0, 'b'), (0, 0, 'c')]
sage: G.delete_edge((0,0,'b'))
sage: G.add_edge((0,0,'d'))
sage: G.edges()
[(0, 0, 'a'), (0, 0, 'c'), (0, 0, 'd')]
Sat, 31 Jan 2015 22:20:30 +0100https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?answer=25660#post-id-25660Comment by vdelecroix for <p>Of course you would have to specify which label will be replaced by <code>'d'</code>. I did not found such a method in Sage (and unfortunately the <code>.set_edge_label()</code> method does not offer the possibility to specify which edge you would like to relabel), but you can always fallback to:</p>
<pre><code>sage: G.edges()
[(0, 0, 'a'), (0, 0, 'b'), (0, 0, 'c')]
sage: G.delete_edge((0,0,'b'))
sage: G.add_edge((0,0,'d'))
sage: G.edges()
[(0, 0, 'a'), (0, 0, 'c'), (0, 0, 'd')]
</code></pre>
https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?comment=25662#post-id-25662@Nathann J'espere que tu as vote pour nous :-DSun, 01 Feb 2015 00:42:31 +0100https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?comment=25662#post-id-25662Comment by Nathann for <p>Of course you would have to specify which label will be replaced by <code>'d'</code>. I did not found such a method in Sage (and unfortunately the <code>.set_edge_label()</code> method does not offer the possibility to specify which edge you would like to relabel), but you can always fallback to:</p>
<pre><code>sage: G.edges()
[(0, 0, 'a'), (0, 0, 'b'), (0, 0, 'c')]
sage: G.delete_edge((0,0,'b'))
sage: G.add_edge((0,0,'d'))
sage: G.edges()
[(0, 0, 'a'), (0, 0, 'c'), (0, 0, 'd')]
</code></pre>
https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?comment=25661#post-id-25661Ptin mais vous vous creez du Karma entre vous maintenant ? :-PPPSun, 01 Feb 2015 00:13:31 +0100https://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/?comment=25661#post-id-25661