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.Wed, 10 Oct 2018 02:04:43 -0500Graph with partial edge labellinghttp://ask.sagemath.org/question/43892/graph-with-partial-edge-labelling/ Hello all,
I need to draw a graph in which some edges are labelled and some edges are not.
I know how to make all the edges labelled. But I need mixed edges (some are labelled and some are not).
Kindly help me with this.
Thank youGA316Wed, 10 Oct 2018 02:04:43 -0500http://ask.sagemath.org/question/43892/creating graph with dotted edgeshttp://ask.sagemath.org/question/43872/creating-graph-with-dotted-edges/ Hello all,
I need to draw a graph in which some edges are usual and some edges are dotted. I know how to make all the edges dotted (using the option "dotted" for the parameter edge_style of plot). But I need mixed edges (some are dotted and some are usual). Kindly help me with this.
Thank you.
GA316Mon, 08 Oct 2018 11:17:43 -0500http://ask.sagemath.org/question/43872/values or names on tree branches (graph)http://ask.sagemath.org/question/43691/values-or-names-on-tree-branches-graph/ Hi
How can I make appear names (or,and) numerical values on the branches ?.
#https://ask.sagemath.org/question/43106/preserving-the-rooted-tree-layout-in-graphs/
G=Graph({1:[2,3],2:[4,5],3:[6,7]})
G.weighted(False)
G.show(layout='tree',tree_root=1)
show(G.vertices())ortolljTue, 18 Sep 2018 06:33:09 -0500http://ask.sagemath.org/question/43691/Why can't I find the spectral radius of a tree?http://ask.sagemath.org/question/43496/why-cant-i-find-the-spectral-radius-of-a-tree/ If I create some connected graphs, and ask SageMath for their spectral radius, the command never returns (well, I have only let it run for a few minutes) if the target is a tree.
Here is a simple example:
g = graphs.CompleteBipartiteGraph(1,3)
print g.spectrum()
print g.spectral_radius()
The only advertised requirement for the target is that it be strongly connected, but as it is a connected graph, this should automatically be satisfied.
Yes, I can work around by computing the spectrum and taking the biggest, but I'd still like to know why this does not work.GordonMon, 27 Aug 2018 22:23:37 -0500http://ask.sagemath.org/question/43496/class of trees or graphshttp://ask.sagemath.org/question/43454/class-of-trees-or-graphs/ [Here](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/trees.html) we can see how to generate all the trees of order $n$ and is not upto isomorphism. But I dont want all trees of order $n$.
I want to know is there class of graphs which are particular typres of trees, like class of paths.
In general where I can find how to define class of complete graph, cycles, . . .
Kindly share the link for the documentation.
Thank you.GA316Thu, 23 Aug 2018 22:10:09 -0500http://ask.sagemath.org/question/43454/How can I generate a graph from an .mtx file?http://ask.sagemath.org/question/42866/how-can-i-generate-a-graph-from-an-mtx-file/The .mtx file contains the information of an sparse matrix in matrix market format. How can I generate the underlying graph of this matrix in SAGE?
Alternatively, since I now how to generate the .mat file from .mtx file in MATLAB, how can I generate the graph from .mat file in SAGE?
The matrix in .mtx in format is the adjacency matrix of the graph. The problem is I cannot read the matrix and generate the underlying graph in SAGE 8.2 (Jupyter).ASHSun, 08 Jul 2018 23:13:44 -0500http://ask.sagemath.org/question/42866/Show3d has no partition optionhttp://ask.sagemath.org/question/42820/show3d-has-no-partition-option/ `graph.show(partition = Pi)` works but `graph.show3d(partition =Pi)` doesn't. Is this something that might be fixed in the future? Or is there a workaround? Bjørn Kjos-HanssenWed, 04 Jul 2018 02:19:18 -0500http://ask.sagemath.org/question/42820/Automorphism group of weighted graphhttp://ask.sagemath.org/question/42762/automorphism-group-of-weighted-graph/I know we can use sage to find the group of automorphisms of a graph $G$:
G.automorphism_group().list()
However, the above way can only be used to the unweighted graph. So for example:
G = matrix([[0,10,0],
[10,0,1],
[0,1,0]])
G1 = Graph(G, weighted = True)
G1.show(edge_labels=True )
G.automorphism_group().list()
The result is:
[(), (0,2)]
However, this result is not correct (correct for unweighted case). This is because $AD\neq DA$, where
$$D = \begin{bmatrix} 0 & 0 & 1 \\\ 0 & 1 & 0 \\\ 1 & 0 & 0\end{bmatrix},$$ which is a permutation matrix and
$$A = \begin{bmatrix} 0 & 10 & 0 \\\ 10 & 0 & 1 \\\ 0 & 1 & 0\end{bmatrix},$$ which is an adjacency matrix.
Can we use SAGE to find the group of automorphisms of a graph?sleeve chenWed, 27 Jun 2018 20:22:14 -0500http://ask.sagemath.org/question/42762/Problem with .stl and Graphhttp://ask.sagemath.org/question/41702/problem-with-stl-and-graph/Hi everyone!
I have a problem with SageMath, and I need your help :).
I want to save my personal Graph from a list to a .stl file
(.stl for 3d object representation, "stereolithography").
My code:
p = [[0,0,0],[1,2,3],[2,3,1],[2,1,0],[1,3,2],[3,2,1]]
points = PointConfiguration(p)
triang = points.triangulate()
triang.save('mygraph.stl')
triang.plot(axes=False)
___
When I try to save my file it's in the .sobj extension. (I research this extension
and it's just an extension SageObject, so it's not useful for me). I want to draw
a graph with a list of point and to convert them in a .stl file.
I already tried:
- save the plot:
triang.plot().save('mygraph.stl') # Fails as there is no attribute face_list
- save the all[-1]:
triang.all[-1].save('test.stl') # Fails as PointConfiguration don't have argument all.
I don't know what is the problem, so I ask for your help.
Thank you very much.haaggenWed, 21 Mar 2018 15:48:59 -0500http://ask.sagemath.org/question/41702/Flow gives error for disconnected verticeshttp://ask.sagemath.org/question/41419/flow-gives-error-for-disconnected-vertices/ When calculating the flow between to vertices which are not connected in a graph, the method returns a ValueError. I would have assumed that it would just return 0. Here's a minimal example:
G=Graph({0:[],1:[]})
G.flow(0,1) # raises the error ValueError: vertex '0' is not in the (di)graph
If on the other hand one tries the shortest_path method it just returns a empty list, since there is not path between 0 and 1.
G.shortest_path(0,1) #returns []AckslWed, 07 Mar 2018 06:21:06 -0600http://ask.sagemath.org/question/41419/How to write the given program in sagehttp://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/I am new to sage. I have learned the basics of sage programming from various online notes.
I am interested to apply sage in linear algebra and graph theory.
My problem is I want to draw a graph as follows:
Vertices : Subspaces of a vector space of dimension $n$.
Edges: $V_1V_2\iff V_1 \subset V_2$ or $V_2\subset V_1$.
Please don't give me the solution.
Please help me how to write it step by step or give some resources from where I can find this.
CaptchaMon, 26 Feb 2018 21:53:00 -0600http://ask.sagemath.org/question/41274/Import error with pydotplushttp://ask.sagemath.org/question/41078/import-error-with-pydotplus/ Hello,
I am running Sagemath 7.3 on Linux. I would like to export a graph using the export function of the graph, but I get the error
`
ImportError: No module named pydotplus`
The python module pydotplus was already installed with `pip install pydotplus`
I cannot find any help regarding this issue. Any suggestion?
Thank you in advance for your helpluno_TMon, 12 Feb 2018 07:55:11 -0600http://ask.sagemath.org/question/41078/shortest pathhttp://ask.sagemath.org/question/40267/shortest-path/Hi, I wanna find the best route by minimizing the cost form 4a to 1a,
I write this code in Cocalc
G = Graph({"1a": {"2a": 521916, "22a": 182390, "23a": 144448, "44a": 1199260, "101a": 73200},
"23a": {"24a": 200324,"101a": 193980},
"2a": {"3a": 193980},
"3a": {"4a": 176900},
"4a" : {"5a":78080},
"5a" : {"6a":599386},
"6a" : {"7a":633180, "30a":845582},
"7a":{"8a":293532},
"8a":{"9a":197030, "32a":562420},
"9a":{"10a":97600},
"10a":{"17a":154940},
"9a":{"16a":342820},
"16a":{"17a":354898,"18a":164578, "15a":309880,"18a":164578},
"15a":{"14a":592920},
"18a":{"19a":147559},
"19a":{"20a":338550},
"20a":{"21a":190930},
"21a":{"7a":26230},
"32a":{"31a":207400},
"11a":{"12a":498980},
"33a":{"34a":378200},
"34a":{"35a":196176},
"30a":{"28a":200080},
"28a":{"29a":390888},
"29a":{"25a":462136},
"25a":{"26a":536800},
"2a":{"25a":183000},
"26a":{"27a":694790},
"27a":{"28a":747128},
"27a":{"41a":317200},
"41a":{"42a":451400},
"42a":{"12a":85400},
"41a":{"40a":660020},
"42a":{"44a":500566},
"12a":{"64a":231800},
"64a":{"65a":505568},
"45a":{"46a":581696},
"46a":{"47a":819352},
"47a":{"48a":486292},
"48a":{"49a":466406},
"49a":{"50a":292800},
"50a":{"51a":744200},
"51a":{"52a":256200},
"52a":{"53a":573400},
"52a":{"54a":744200},
"54a":{"55a":195200},
"55a":{"56a":689300},
"55a":{"62a":366000},
"62a":{"63a":793000},
"56a":{"57a":183000},
"57a":{"58a":149084},
"58a":{"59a":390400},
"59a":{"60a":265960},
"60a":{"61a":378810},
"66a":{"67a":504470},
"67a":{"68a":245830},
"68a":{"69a":213500},
"69a":{"70a":256200},
"67a":{"71a":833138},
"71a":{"72a":686860},
"72a":{"73a":732000},
"73a":{"74a":305000},
"74a":{"75a":207400},
"72a":{"76a":479460},
"76a":{"77a":183000},
"77a":{"78a":512400},
"71a":{"84a":131760},
"84a":{"83a":466040},
"83a":{"85a":187880},
"83a":{"82a":453840},
"82a":{"81a":376980},
"81a":{"80a":451400},
"80a":{"79a":368074},
"85a":{"86a":543266},
"86a":{"87a":513742},
"87a":{"88a":699426},
"88a":{"89a":685030},
"89a":{"90a":386130},
"89a":{"91a":451400},
"91a":{"92a":669170},
"92a":{"93a":313784},
"93a":{"94a":12.2},
"93a":{"95a":548024},
"95a":{"96a":45140},
"86a":{"97a":319640},
"36a":{"37a":31720},
"98a":{"99a":488000},
"98a":{"39a":644770},
"39a":{"43a":435906},
"49a":{"57a":399916},
"23a":{"101a":193980},
"101a":{"1a":73200},
"2a":{"25a":183000},
"23b":{"101b":82200},
"101b":{"25b":373800},
"25b":{"3b":63000},
"3b":{"4b":245400},
"4b":{"6b":202800},
"6b":{"7b":180000},
"7b":{"8b":220800},
"8b":{"13b":246000},
"23a":{"23b":250000},
"101b":{"101a":250000},
"25b":{"25a":250000},
"3b":{"3a":250000},
"4b":{"4a":250000},
"6b":{"6a":250000},
"7b":{"7a":250000},
"8b":{"8a":250000},
"13b":{"13a":250000}})
G.plot(edge_labels=True).show() # long time
G.shortest_path("4a", "1a", by_weight=True)
<change> I mean I wrote G.shortest_path("4a", "1a", by_weight=True) instead of G.shortest_path("3a", "2a", by_weight=True)
but it gives me 4a,5a,6a,30a, 28a, 29a, 25a, 2a,1a (which is not the best route)
because i try to manually calculate and there's a better route which is 4a, 3a, 2a, 1a
so, why this g.shortest_path doesn't give me the shortest one?
n btw what's the command to print/show the total cost of the chosen shortest path?
Thanks, Astra
Ps. I'm new to sagemathAstra BeThu, 21 Dec 2017 03:01:47 -0600http://ask.sagemath.org/question/40267/find embedded subgraphshttp://ask.sagemath.org/question/40140/find-embedded-subgraphs/Hi there,
is there a method to find all embedded copies of a graph in another graph, e.g. given two graphs H and G I want something like:
G = graphs.RandomGNP(10,.3) #some graph
H = Graph({1:[1,2], 2:[1,2]}) #some other graph
list = G.find_subgraphs(H, homeomorphic=False/True)
Where the elements list are all the subgraphs in G which are isomorphic/homeomorphic to H.
If this is too much to ask for, there should be at least a method to return all cycles in G (i.e. closed paths in G with each vertex at most once). Since there exists the Hamiltonian cycle method this one should exist too.
PS: In my case the graph has multiedges (and loops, but we can ignore this here).ctstWed, 13 Dec 2017 09:13:56 -0600http://ask.sagemath.org/question/40140/Plotting a frequency chart from a set of valueshttp://ask.sagemath.org/question/39677/plotting-a-frequency-chart-from-a-set-of-values/Hello,
I have got a list of results from my function already. And now, I need to visualise this information and plot a chart of how many times each particular value is repeated in a list. I know how to do a histogram, but it shows intervals of values, but not specific values. I need to access all the values afterwards as well and be able to work with them.
----------
I have found also that I can count values using a command "count"
`list.count()` if it is necessary to do it like this in my problem.
I'd like to ask what is the code for such frequency chart (or plot of points)? And how do I need to define my variables?
Would be much appreciated if someone could help in any way. Thank you very much.
XeniaXeniaMon, 20 Nov 2017 12:12:52 -0600http://ask.sagemath.org/question/39677/Graphing ineqalitieshttp://ask.sagemath.org/question/39216/graphing-ineqalities/ So I'm trying to graph the inequality x+y+3u>=0
I want to keep the u fixed, but I'm having issues finding out how to do that.
Also, I was wondering if it would be possible to have some type of dynamic slider for u, so that this way I can change the value of u.kaylavb23Thu, 19 Oct 2017 09:37:54 -0500http://ask.sagemath.org/question/39216/Edge color for undirected multiedge graphshttp://ask.sagemath.org/question/39153/edge-color-for-undirected-multiedge-graphs/ It seems that there is a bug with specifying the color of undirected multiedges. Here's an example:
G=graphs.PathGraph(2)
G.allow_multiple_edges(True)
G.add_edge((0,1))
G.plot(edge_colors={"red":[(1,0)]})
The graph plotted has then four edges, two black and two red. It seems that the multiedge to be colored red is seen as a different one than the already present one, even though they are actually the same since the graph is undirected. I get the intended plot if I change the last line to:
G.plot(edge_colors={"red":[(0,1)]})AckslFri, 13 Oct 2017 09:00:23 -0500http://ask.sagemath.org/question/39153/Stochastic block modelhttp://ask.sagemath.org/question/38929/stochastic-block-model/Hi all,
I would like to draw a random graph by Sage. The general stochastic model is the following: The graph contains $n$ vertices and the n vertices are divided into $r$ communities $C_1\cdots,C_r$. For two vertices within the same community, there is a probability $P_r$ that they are connected directly by an edge. How do I plot such a graph in Sage? References appreciated.Dianbin BaoThu, 21 Sep 2017 13:19:26 -0500http://ask.sagemath.org/question/38929/Paths beginning with a certain vertexhttp://ask.sagemath.org/question/38452/paths-beginning-with-a-certain-vertex/So I have a graph $G$ and a distinguished vertex, labeled with $0$ say. I would like to create a list of all paths of length $k$ that start with $0$.
One way I see how to do this with subgraph_search is to change $0$ into a large clique (larger than the clique number of $G$) and then use subgraph_search_iterator to find all subgraphs with a large clique connected to a path of length $k-1$. However, this seems pretty inefficient. Is there a better way?
vukovMon, 31 Jul 2017 17:09:40 -0500http://ask.sagemath.org/question/38452/Random block graphhttp://ask.sagemath.org/question/37433/random-block-graph/ How can I get a random connected graph with m blocks so that each block is a k-clique (complete graph with k vertices). Deepak SarmaWed, 26 Apr 2017 06:35:00 -0500http://ask.sagemath.org/question/37433/Updating graph plothttp://ask.sagemath.org/question/36342/updating-graph-plot/I wish to visualize a algorithm running on a graph. How can I update the plot of a graph after for example deleting a vertex or to change color of a vertex without generating another plot window?AckslThu, 19 Jan 2017 02:29:05 -0600http://ask.sagemath.org/question/36342/How can I count the number of cycles of special length in a graph in sage?http://ask.sagemath.org/question/35837/how-can-i-count-the-number-of-cycles-of-special-length-in-a-graph-in-sage/I have tried the `G.subgraph_search_count(graphs.CycleGraph(4))`but it doesn't lead to the correct answer,
any help would be appreciated.M95Thu, 01 Dec 2016 02:07:54 -0600http://ask.sagemath.org/question/35837/How do I write function to test if a graph is apex?http://ask.sagemath.org/question/35112/how-do-i-write-function-to-test-if-a-graph-is-apex/ I am working on topological graph theory problems and using SageMath.
I want to create a function that give a boolean True or False answer, so I can use this answer for further use.
My current function that I use:
def is_apex(a):
for v in a.vertex_iterator():
l=a.neighbors(v)
if a.is_planar(a.delete_vertex(v)):
print("Deleting vertex ",v," makes a planar graph")
a.add_vertex(v)
a.add_edges([(v, y) for y in l])
else:
a.add_vertex(v)
a.add_edges([(v, y) for y in l])
print("Deleting vertex ",v," does not make a planar graph")
I am a noob when it comes to programming, and any help would be awesome.
I want a True returned if the graph is apex and a False value to return for not apex.
Thoughts?fieldofnodesMon, 10 Oct 2016 15:18:52 -0500http://ask.sagemath.org/question/35112/How to convert (some particular) Sage objects into Macaulay2 oneshttp://ask.sagemath.org/question/33975/how-to-convert-some-particular-sage-objects-into-macaulay2-ones/ Hi,
I do some calculations about graphs and ideals via M2 interface of Sage or just using M2, but for that, I have to use M2 input as below:
sage: macaulay2('loadPackage "Graphs"')
sage: macaulay2('G = graph({{1,2},{2,3},{3,4}})')
as explained in the Macaulay2 web page.
Is there a way to convert a graph or an ideal written in Sage code into Maculay2 ones so that it can be employed in M2 interface. For instance,
sage: d={1:[2], 2:[1,3], 3:[2,4], 4:[3]}
sage: G = Graph(d)
sage: macaulay2('H=graph(G)') (or H=macaulay2('graph(G)'))
Of course M2 won't accept my silly code in the 3rd line, but I've tried various ways like injecting a square free-quadratic-monomial ideal or edge list of a graph into M2 and I always fail.
I also have the same problem for ideals.
It's a long-standing problem of mine and it costs me writing heavy codes in Sage for multiple calculations. Calculating via M2 with Sage inputs will save lots of my time.
Can anyone help?
Thanks in advance! :)
Best Regards
MehmetMehmet Akif YetimThu, 30 Jun 2016 05:03:45 -0500http://ask.sagemath.org/question/33975/Make graph from matrixhttp://ask.sagemath.org/question/33903/make-graph-from-matrix/Hi,
I'm a new user of SageMath and maybe my question is very simple or already answered somewhere but I wasn't able to find an answer to my problem. For my studies I have to implement a brute-force algorithm for solving the travelling salesman problem. I found out, that SM already has a solver for this problem that handles Graph - objects. I wan't to use it to check the results of my algorithm. I wrote some input data as a dictionary to feed into both alg, but if I wan't to do it for more than a few cities (I can handle only a few with bruteforce anyway because of the time it takes to calculate all the possibilities) and I've found a matrix with distances between cities. It is available here
https:// people.sc.fsu.edu/~jburkardt/datasets/cities/cities.html
(ha30_dist.txt)
I threw the first two lines out and I can import this file with numpy.loadtxt(). But later, when I try to make Graph using this matrix, I get the error:
*"ValueError: There must be one or two nonzero entries per column in an incidence matrix. Got entries [39, 22, 59, 54..."*. What am I doing wrong?
GreetingslittlemdThu, 23 Jun 2016 14:56:02 -0500http://ask.sagemath.org/question/33903/show() does not show in the right placehttp://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/ Why the show() funtion does not show in the right position?
It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)
print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)stefanuttiTue, 31 May 2016 03:36:00 -0500http://ask.sagemath.org/question/33593/How do I get the external face of a planar embedded graph?http://ask.sagemath.org/question/33363/how-do-i-get-the-external-face-of-a-planar-embedded-graph/ First of all I am new to Sage and Python.
I need to get the external face a planar embedding and I immagined that it is always the first element returned by the function faces().
But in this example it seems to change. See the first and the second run.
Is it something about the function faces() or an error in this program?
print ("--- Create a graph")
G = Graph(sparse=True)
G.add_edge(1,2,"1-2")
G.add_edge(2,3,"2-3")
G.add_edge(3,4,"3-4")
G.add_edge(4,5,"4-5")
G.add_edge(5,1,"5-1")
G.add_edge(1,6,"1-6")
G.add_edge(2,10,"2-10")
G.add_edge(3,12,"3-12")
G.add_edge(4,11,"4-11")
G.add_edge(5,7,"5-7")
G.add_edge(6,7,"6-7")
G.add_edge(6,8,"6-8")
G.add_edge(8,10,"8-10")
G.add_edge(10,12,"10-12")
G.add_edge(12,11,"12-11")
G.add_edge(7,9,"7-9")
G.add_edge(8,9,"8-9")
G.add_edge(9,11,"9-11")
print ("--- Embed on a plane")
void = G.layout(layout = "planar", save_pos = True)
G.plot()
# Kempe reduction: for each loop remove an edge from faces <= F5
#
while len(G.faces()) > 2:
print ("Number of faces: ", len(G.faces()))
# Remove the external face. Is it always faces[0]???
#
faces = G.faces()
externalFace = faces[0]
facesWithoutTheExternalFace = copy(faces)
facesWithoutTheExternalFace.remove(externalFace)
print ("faces: ", faces)
print ("externalFace: ", externalFace)
print ("facesWithoutTheExternalFace: ", facesWithoutTheExternalFace)
# Find the fist face [0] with len <= 5. It always exists: unavoidable set
#
faceToReduce = [x for x in facesWithoutTheExternalFace if len(x) <= 5][0]
print ("Face <= 5: ", faceToReduce)
# Find the first edge of the faceToReduce that is not on an edge on the external face
#
edgeToRemove = [x for x in faceToReduce if not x in externalFace][0]
print ("edgeToRemove: ", edgeToRemove)
verticesToRemove = G.get_vertices(edgeToRemove)
print ("verticesToRemove ", verticesToRemove)
G.delete_edge(edgeToRemove)
neighborsOfTheFirstVertex = G.neighbors(verticesToRemove.keys()[0])
neighborsOfTheSecondVertex = G.neighbors(verticesToRemove.keys()[1])
print ("neighborsOfTheFirstVertex = ", neighborsOfTheFirstVertex)
print ("neighborsOfTheSecondVertex = ", neighborsOfTheSecondVertex)
G.delete_vertices(verticesToRemove)
G.add_edge(neighborsOfTheFirstVertex[0], neighborsOfTheFirstVertex[1])
G.add_edge(neighborsOfTheSecondVertex[0], neighborsOfTheSecondVertex[1])
G.plot()stefanuttiWed, 11 May 2016 03:44:18 -0500http://ask.sagemath.org/question/33363/edge_style for different edges in a multigraphhttp://ask.sagemath.org/question/33228/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!mthomasMon, 25 Apr 2016 19:17:33 -0500http://ask.sagemath.org/question/33228/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/For graphing, associating custom x-values with each Y?http://ask.sagemath.org/question/32781/for-graphing-associating-custom-x-values-with-each-y/ Hello, all. This is my first time posting here, as I am new with Sage and have only started learning it this semester for a math class. So far I really love it.
I'm pretty sure this is a very basic question, but please bear with me. I have a set of Y-values in a given sequence that I would like to graph, which would normally not be a problem with "finance.TimeSeries," but I want to associate a custom set of X-values with the Y-values to be used in the graphing, and not x=o up to however far away my last Y-value is. For ex., I have Y's = [1, 2, 4, 6], and would like to graph [(3, 1), (2, 2), (12, 4), (5, 6)], instead of [(0, 1), (1, 2), (2, 4), (3, 6)].
Thanks to any replies in advance.mziedalskiSat, 12 Mar 2016 17:34:02 -0600http://ask.sagemath.org/question/32781/