ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 09 Jan 2020 09:09:44 -0600How to find the sum weight on a vertexhttp://ask.sagemath.org/question/49473/how-to-find-the-sum-weight-on-a-vertex/ Hi
I want to define a random labeling on edges of a graph (without duplicate labels ) and then find the sum of the weights of incident edges to each vertex.
Here is code I wrote:
n=[]
import random
W=random.sample(G.num_edges(),G.num_edges())
w_edges = [(E[i][0], E[i][1], W[i]) for i in xrange(q)]
for i in G.vertex_iterator():
x=sum(W[k] for k in G.neighbor_iterator(i))
n.append(x)
But I receive some errors. I'll be happy if you can help me.
MiladThu, 09 Jan 2020 09:09:44 -0600http://ask.sagemath.org/question/49473/Position of labels in a graphhttp://ask.sagemath.org/question/33025/position-of-labels-in-a-graph/I'm creating a labeled graph, but the position of the labels is making them difficult to read. For example:
D = DiGraph(multiedges=True)
D.add_edge(var('Vert1'),var('Vert2'),str("Edge1"))
D.add_edge(var('Vert2'),var('Vert3'),str("Edge2"))
D.add_edge(var('Vert1'),var('Vert3'),str("Edge3"))
D.graphplot(edge_labels=True,layout='circular').show()
creates a nice looking graph, but especially `Edge1` is difficult to read. Is there a way to move labels away from the edges?
I know there are posts asking similar questions (insufficient karma to post links), though these suggest changing the rule for label location to be something other than the middle of the two points, and I'd rather not have to use the same rule for all labels, as the changes may be different for different vertices.
EDIT: I have a sort-of solution, which is just to add spaces in the label name or line breaks in the label name, which does achieve the goal, but if someone has a better solution, I would be very happy to hear it. E.g.:
D = DiGraph(multiedges=True)
D.add_edge(var('Vert1'),var('Vert2'),str("""Edge1
"""))
D.add_edge(var('Vert2'),var('Vert3'),str(" Edge2"))
D.add_edge(var('Vert1'),var('Vert3'),str(" Edge3"))
D.graphplot(edge_labels=True,layout='circular').show()
mthomasWed, 06 Apr 2016 16:30:18 -0500http://ask.sagemath.org/question/33025/labelling the edges of posethttp://ask.sagemath.org/question/29820/labelling-the-edges-of-poset/ P = SetPartitions(3)
f = lambda q,p: q in p.refinements()
Po = Poset((P,f))
By using this command I have defined a poset in sage.
Po.show() displays the poset as a directed graph. My question is how to put labels to edges of this graph.
when I try to do so, I try to iterate over the edge set like:
for u in Po.edges() :
but sage saying the error message that poset object has no method edges.
Can any one tell me how to put label for this directed graph.
If we define the corresponding Hasse diagram then we can define label, but I want to do label for the edges in the poset but not for the edges in the Hasse diagram. because when we display the pose it looks nice to see, but when we print Hasse diagram it looks little messy.
Thanks for your valuable time.GA316Thu, 08 Oct 2015 02:26:00 -0500http://ask.sagemath.org/question/29820/How can I search and count all induced subgraphs in a directed graph with edge labels?http://ask.sagemath.org/question/26630/how-can-i-search-and-count-all-induced-subgraphs-in-a-directed-graph-with-edge-labels/Hello all,
I can extract all induced subgraphs and count them in a graph. My question is how I can search and count all induced subgraphs in a labeled graph (a graph with edge labels)? In documentation of g.subgraph() and g.subgraph_search_count() is mentioned that these functions should work on labeled graphs as well. but it does not work. Here is an example:
sage: g=DiGraph()
sage: g.add_vertex(0)
sage: g.add_vertex(1)
sage: g.add_vertex(2)
sage: g.add_edge(0,1,label="a")
sage: g.add_edge(1,2,label="b")
sage: g.plot(color_by_label="true")
sage: g.plot(color_by_label=true)
sage: s=DiGraph()
sage: s.add_vertex(0)
sage: s.add_vertex(1)
sage: s.add_edge(0,1,label="a")
sage: s.plot(color_by_label=true)
sage: g.subgraph_search_count(s)
2
While it should return 1 not 2.
bsstenissThu, 23 Apr 2015 05:29:44 -0500http://ask.sagemath.org/question/26630/how do I set label of multiedges graphhttp://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.
VincentvdelecroixSat, 31 Jan 2015 14:01:13 -0600http://ask.sagemath.org/question/25659/edge labels and vertex size causes problemshttp://ask.sagemath.org/question/10776/edge-labels-and-vertex-size-causes-problems/Hi,
I have several problems creating a graph. I want to misuse the graph tools in sagemath to create a flow diagram, but I encountered two problems:
First, the vertex_size option does not work at all in my code and
second, relating to the question
[here](http://ask.sagemath.org/question/1700/getting-edge-labels-in-a-digraph-to-display), is there now a possibility to shift the edge labels?
I work with sage 5.9 in a virtual box environment
from sage.graphs.graph_plot import GraphPlot
h = DiGraph({0:[1,2], 1:[3], 2:[4]})
for u,v,l in h.edges():
h.set_edge_label(u,v,'(' + str(u) + ',' + str(v) + ')')
h1=h.graphplot(save_pos=True, edge_labels=True, talk=True)
h1.show()
print h.get_pos()
h.set_pos({0:[0,0],1:[1,1],2:[1,-1],3:[2,1],4:[3,-1]})
h1=h.graphplot(save_pos=True, edge_labels=True, talk=True, vertex_size=0)
h1.set_vertices(vertex_shape='s')
h1.show()
Thanks in advance.god.oneMon, 25 Nov 2013 21:33:26 -0600http://ask.sagemath.org/question/10776/Labeling in graphshttp://ask.sagemath.org/question/10326/labeling-in-graphs/I am new to SAGE and am trying to experiment with it. What I am trying to do is something like this -
k = 1
G.add_edge((1,2), label= 'k')
Then it should label the edge as '1', not as 'k'. How would I do this?sanjithSat, 06 Jul 2013 09:02:35 -0500http://ask.sagemath.org/question/10326/DiGraph labels?http://ask.sagemath.org/question/7838/digraph-labels/Labels don't seem to work on DiGraphs. For example:
> g=DiGraph(vertex_labels=True)
> g.add_edge(2,3,label="label")
> g.show()
This just shows 2 and 3 as labels. Is this a bug or am I doing something wrong?
Thanks in advance.Eviatar BachSun, 02 Jan 2011 11:45:55 -0600http://ask.sagemath.org/question/7838/