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, 21 Mar 2018 15:48:59 -0500Problem 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/Changing vertex labels on a randomly generated graphhttp://ask.sagemath.org/question/32702/changing-vertex-labels-on-a-randomly-generated-graph/ I know that if I want to create a graph on 4 vertices with vertex labels 1,2,3,4 then I can define my graph like this:
G = Graph({0: [1, 3], 1: [2, 3,4], 2: [1,4], 3: [], 4: []})
and then when I print in LaTeX using sagetex the labels show up as 1,2,3,4 but when I try to create a graph randomly
graphs.RandomGNM(4,5)).show(figsize=[4,4], graph_border=True)
the vertex labels are 0,1,2,3. How do I change the default vertex labels of a randomly created graph?dazedANDconfusedThu, 03 Mar 2016 09:06:39 -0600http://ask.sagemath.org/question/32702/Change the edge thickness in a graph plothttp://ask.sagemath.org/question/32251/change-the-edge-thickness-in-a-graph-plot/I want to plot a graph with many edges, but they just end up looking like a black mass. I can see how to change vertex size and whatnot but not edge thickness.
sage: H=graphs.CompleteGraph(100)
sage: H.show()
Launched png viewer for Graphics object consisting of 5051 graphics primitives
Not sure where my karma went, but you can guess what this looks like.lutherdriggersSun, 17 Jan 2016 07:23:52 -0600http://ask.sagemath.org/question/32251/Convert graph into ideal in polynomial ringhttp://ask.sagemath.org/question/32165/convert-graph-into-ideal-in-polynomial-ring/ Let $G = (V (G), E(G))$ denote a finite simple (no loops or multiple edges) undirected
graph with vertices $V (G) =\ {x_1 ,\ldots, x_n \}$ and edge set $E(G)$ . By identifying the vertices
with the variables in the polynomial ring $R = k[x_1 ,\ldots, x_n ]$ (where $k$ is a field), we can
associate to each simple graph $G$ a monomial ideal $ I(G) = (\{ x_i x_j |\{x_i , x_j \} \in E(G)\})$
How to convert graph into ideal in sage ?
Suppose $G$ is cycle graph. can i get ideal with generator $(x_1x_2,x_2x_3,x_3x_4,x_4x_5,x_1x_5)$ in $k[x_1,\ldots
,x_5]$
Please give some hint.
Thanks in advanceselvaTue, 12 Jan 2016 05:11:16 -0600http://ask.sagemath.org/question/32165/Tree layout of a graphhttp://ask.sagemath.org/question/31513/tree-layout-of-a-graph/ Consider the graph of this tree:
T = Graph()
E = [(0, 1), (1, 2), (2, 3), (2, 4)]
T.add_edges(E);
T.show(layout='tree',tree_root=0,tree_orientation='down')
![image description](/upfiles/14499200675194864.png)
I would like to see the edges displayed in the order as given in the list E from left to right.
In other words, I would like to have node(4) exchange its position with node(3).
How can I achieve this?
*Edit:* To clarify: Changing the order of the edge-list is no option
(besides not working either). The order of the edges must be adhered
to the order given.Peter LuschnySat, 12 Dec 2015 05:42:23 -0600http://ask.sagemath.org/question/31513/Dotted and dashed lines in directed graphshttp://ask.sagemath.org/question/31304/dotted-and-dashed-lines-in-directed-graphs/Hi,
I would like to know if it is possible to do (one of) the following with Sage.
Reading
http://doc.sagemath.org/html/en/reference/plotting/sage/graphs/graph_plot.html
I saw that it is possible to draw dashed and dotted lines. Now my questions are
1) Is it possible to produce an output graphic where some edges are dotted and some edges are dashed?
2) Is it possible to force the text in the labels of the vertices, e.g. M2, M4, M1 instead of 0,1,2?
Thanks for the help!
BernThu, 03 Dec 2015 20:39:18 -0600http://ask.sagemath.org/question/31304/Unable to simplify function outputhttp://ask.sagemath.org/question/30155/unable-to-simplify-function-output/ I am trying to make a tool that creates a large number of rectangular boxes approximating a 3 dimensional graph.
However when I enter in my function value as box height Sage says it is unable to simplify my height to a float approximation. I also do not what to display graph when the bounds are not real numbers. Does anyone know the solutions to my two problems.
if lower_x_bound in RR or upper_x_bound in RR or lower_y_bound in RR or lower_y_bound in RR:
#check if bounds are are real before graphing because I do nto know how to graph with x as a bound.
showGraph = True
html("Can only grah numerical bounds")
else:
showGraph = False
if showGraph == True :
graph = plot3d(function,(x,lower_x_bound,upper_x_bound),(y,lower_y_bound,upper_y_bound),fill=True,color = "orange",spin = 4)
html("<h3>Graph of Integrated Region</h3>")
delta = upper_x_bound - lower_x_bound
#func= function(x = lower_x_bound+(i-1)*delta/numrecs , y = .2)
#show(func)
B = sum([Box([1/numrecs,.5,function(x = lower_x_bound+(i-1)*delta/numrecs , y = .2)], color="orange").translate((lower_x_bound+delta*i/numrecs,0,function(lower_x_bound+i*delta/numrecs)/2)) for i in [0..numrecs]])
#makes a whole bunch of rectangels which approximate graph of function being integrated
show(graph+B)
This is the error I get when it tries to make the box heights.
Error in lines 1-1
Traceback (most recent call last):
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_server.py", line 881, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_server.py", line 1031, in _execute_interact
sage_salvus.interacts[id](vals)
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_salvus.py", line 216, in __call__
self._f(**dict([(k,self._last_vals[k]) for k in self._args]))
File "", line 26, in interplay
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_salvus.py", line 2429, in show
s = show0(objs, combine_all=True)
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_salvus.py", line 2414, in show0
b = show0(a)
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_salvus.py", line 2402, in show0
salvus.threed(obj, **kwds)
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_server.py", line 657, in threed
b = g.bounding_box()
File "sage/plot/plot3d/base.pyx", line 1826, in sage.plot.plot3d.base.Graphics3dGroup.bounding_box (/projects/sage/sage-6.9/src/build/cythonized/sage/plot/plot3d/base.c:21855)
v = [obj.bounding_box() for obj in self.all]
File "sage/plot/plot3d/base.pyx", line 2053, in sage.plot.plot3d.base.TransformGroup.bounding_box (/projects/sage/sage-6.9/src/build/cythonized/sage/plot/plot3d/base.c:24768)
cdef Transformation T = self.get_transformation()
File "sage/plot/plot3d/base.pyx", line 2174, in sage.plot.plot3d.base.TransformGroup.get_transformation (/projects/sage/sage-6.9/src/build/cythonized/sage/plot/plot3d/base.c:26552)
self.T = Transformation(self._scale, self._rot, self._trans)
File "sage/plot/plot3d/transform.pyx", line 49, in sage.plot.plot3d.transform.Transformation.__init__ (/projects/sage/sage-6.9/src/build/cythonized/sage/plot/plot3d/transform.c:2785)
self.matrix = m.augment(matrix(RDF, 3, 1, list(trans))) \
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/matrix/constructor.py", line 729, in _matrix_constructor
return matrix_space.MatrixSpace(ring, nrows, ncols, sparse=sparse)(entries)
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/matrix/matrix_space.py", line 524, in __call__
return self.matrix(entries, coerce, copy)
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/matrix/matrix_space.py", line 1442, in matrix
return MC(self, x, copy=copy, coerce=coerce)
File "sage/matrix/matrix_double_dense.pyx", line 234, in sage.matrix.matrix_double_dense.Matrix_double_dense.__init__ (/projects/sage/sage-6.9/src/build/cythonized/sage/matrix/matrix_double_dense.c:3798)
self.set_unsafe(i,j,self._python_dtype(entries[i*self._ncols+j]))
File "sage/symbolic/expression.pyx", line 1368, in sage.symbolic.expression.Expression.__float__ (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/expression.cpp:10216)
raise TypeError("unable to simplify to float approximation")
TypeError: unable to simplify to float approximation
This the error with non real bounds like x where I include the graph but not the boxes
Traceback (most recent call last):
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_server.py", line 881, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_server.py", line 1031, in _execute_interact
sage_salvus.interacts[id](vals)
File "/projects/454b81d2-ef23-4b95-bd57-5c718a468ea1/.sagemathcloud/sage_salvus.py", line 216, in __call__
self._f(**dict([(k,self._last_vals[k]) for k in self._args]))
File "", line 19, in interplay
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/plot/plot3d/plot3d.py", line 868, in plot3d
P=parametric_plot3d.parametric_plot3d((u,v,f), urange, vrange, **kwds)
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/plot/plot3d/parametric_plot3d.py", line 594, in parametric_plot3d
G = _parametric_plot3d_surface(f, urange, vrange, plot_points=plot_points, boundary_style=boundary_style, **kwds)
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/plot/plot3d/parametric_plot3d.py", line 704, in _parametric_plot3d_surface
g, ranges = setup_for_eval_on_grid(f, [urange,vrange], plot_points)
File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/plot/misc.py", line 123, in setup_for_eval_on_grid
ranges = [[float(z) for z in r] for r in ranges]
File "sage/symbolic/expression.pyx", line 1368, in sage.symbolic.expression.Expression.__float__ (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/expression.cpp:10216)
raise TypeError("unable to simplify to float approximation")
TypeError: unable to simplify to float approximation
collabmathTue, 20 Oct 2015 14:48:11 -0500http://ask.sagemath.org/question/30155/How to show circular graphs?http://ask.sagemath.org/question/30044/how-to-show-circular-graphs/ Hello,
I'd like to plot a graph (for example, G), but I don't like the random way sage shows it to me. I'd like the vertices of the graph to be on a circular layout. How do I do that?OsloviteThu, 15 Oct 2015 10:40:22 -0500http://ask.sagemath.org/question/30044/how to set latex options on graph to make them ultra small ?http://ask.sagemath.org/question/29488/how-to-set-latex-options-on-graph-to-make-them-ultra-small/I am currently playing with functions indexed by unlabeled graphs. The following method (belonging to my parent class which models linear combinations of graphs) tells my parent how to print basis element indexed by a graph m (m is in fact an integer vector modeling a graph up to isomorphism).
def _latex_term(self, m):
r"""
"""
G = m.to_graph()
opt = G.latex_options()
opt.set_option('tkz_style', 'Simple')
opt.set_option('vertex_labels', False)
opt.set_option('scale', 0.25)
opt.set_option('vertex_size', 0.0)
return '\mathcal{M}_{' + latex(G) + '}'
I tried to set the option 'vertex_size' to zero but the size of the vertex was not affected. I realize that some combinations of options can rapidly become incoherent. Currently, I do not manage to do smaller than in the copy-pasted proposition of code.
I just want a very small (but readable) unlabeled graph.nborieFri, 18 Sep 2015 12:06:18 -0500http://ask.sagemath.org/question/29488/