Ask Your Question

mthomas's profile - activity

2024-02-26 11:06:10 +0200 received badge  Famous Question (source)
2020-12-17 22:25:36 +0200 received badge  Self-Learner (source)
2020-12-17 22:25:36 +0200 received badge  Teacher (source)
2020-12-17 22:24:31 +0200 received badge  Notable Question (source)
2020-01-10 07:16:24 +0200 received badge  Famous Question (source)
2019-06-08 15:35:39 +0200 received badge  Popular Question (source)
2016-08-01 21:57:48 +0200 received badge  Notable Question (source)
2016-08-01 21:57:48 +0200 received badge  Popular Question (source)
2016-04-26 13:24:54 +0200 received badge  Supporter (source)
2016-04-26 13:22:44 +0200 answered a question edge_style for different edges in a multigraph

I'm going to self-post a reasonable solution, in hopes that someone comes up with a better one, which is to use the dist argument in the graph so the edges aren't on top of each other:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.add_edge(A,B,'edge2')
G2.add_edge(A,B,'edge1')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green','edge2':'white'}, edge_style='--', dist=0.75).plot() + G2.graphplot(color_by_label={'edge2':'blue','edge1':'white'}, edge_style=':').plot()
G.show(axes=False)
2016-04-26 02:17:33 +0200 asked a question edge_style for different edges in a multigraph

I'm trying to make a directed multigraph in which different edges have colors/edge styles so that they can be easy read either in color or in black and white.

I can make a graph with different colors:

D = DiGraph(multiedges=True)
var('A,B')
D.add_edge(A,B,'edge1')
D.add_edge(A,B,'edge2')
D.graphplot(color_by_label={'edge1':'green','edge2':'blue'}).show()

I can also make a graph with different styles, but overlayed:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green'}, edge_style='--').plot() + G2.graphplot(color_by_label={'edge2':'blue'}, edge_style=':').plot()
G.show(axes=False)

and a very hack-y solution which looks nicer, but still bad:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.add_edge(A,B,'edge2')
G2.add_edge(A,B,'edge1')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green','edge2':'white'}, edge_style='--').plot() + G2.graphplot(color_by_label={'edge2':'blue','edge1':'white'}, edge_style=':').plot()
G.show(axes=False)

I'd love to be able to have a multigraph where the edges are both different colors and different styles and don't completely overlap, but I'm not seeing a way to do this. Any help is appreciated!

2016-04-07 15:29:29 +0200 received badge  Nice Question (source)
2016-04-07 02:05:24 +0200 received badge  Student (source)
2016-04-06 23:55:39 +0200 asked a question 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()
2015-10-13 17:28:49 +0200 commented answer Counting paths in directed graph with multiedges

This looks great, thank you! I just changed line 9 from A.edge_boundary... to G.edge_boundary.

2015-10-13 17:28:01 +0200 received badge  Scholar (source)
2015-10-12 22:01:09 +0200 asked a question Counting paths in directed graph with multiedges

I would like to could paths in a directed graph with multiedges, where taking a different edge between a given pair of vertices is counted as a new path. For example:

A = DiGraph(multiedges=True)
A.add_edge(1,2,'a')
A.add_edge(1,2,'b')
A.add_edge(2,3,'c')
A.graphplot(edge_labels=True).show()
A.all_paths(1,3)

returns [[1,2,3]]. I would like to have it return 2 paths, ideally listed by the edges instead of the vertices, e.g. [a,c] and [b,c]. Any recommendations?

2015-07-05 21:02:17 +0200 received badge  Editor (source)
2015-07-05 20:59:45 +0200 asked a question Typesetting in sage vs sagecloud

In a local install of sage (v 6.3, fedora 21), if I turn on the typesetting and differentiate a function like x^2*sin(x), everything looks nice. In sage cloud with typeset_mode(True), running

diff(x^2*sin(x),x)

in chrome breaks the output along two lines. It doesn't seem to matter whether the display option is true or false in typeset_mode. Running it in firefox looks fine, just like it does in sage.

I'd like the output in sage cloud to look the way it does in the local install for readability - is there a way to make this happen for chrome, or will I need to use firefox for that?

EDIT: I'm not sure what I've done, other than running both chrome and firefox, but the output in chrome is no longer breaking, so it seems that it's not just the browser.

Thanks in advance, Matt