Working with sage graphics
I have written some code to plot some graphs (that is vertices and edges) and it has been suggested that I am being inefficient. I have say 50-100 primitives (consisting of lines and circles). At the moment I use to Graphics() to create an empty graphics object and then use + to add the primitives. Is there a better way to do this?
Edit The add_primitive() is one improvement. Here is a toy example
n = 10
g = Graphics()
for i in range(n):
for j in range(n):
g += line([(i,j),(i+1,j)])
g += line([(i,j),(i,j+1)])
g.show()
n = 10
g = Graphics()
for i in range(n):
for j in range(n):
g.add_primitive(line([(i,j),(i+1,j)]))
g.add_primitive(line([(i,j),(i,j+1)]))
g.show()
A second question is that I would also like to plot a formal linear combination of these graphs. At the moment I produce a list with a graph and the coefficients (via latex) alternating and then use graphics_array(). However I would prefer to group the primitives in a graph and in the latex and then scale these and place them myself.
Edit This is the code for my second question. The variable a is a formal linear sum (using CombinatorialFreeModule). The function circlepacking takes a graph and produces a graphics object.
r = a.monomial_coefficients()
pics = []
for f in r:
c = r[f]
if c == 1: lt = "$+$"
elif c == -1: lt = "$-$"
else: lt = "$+("+latex(c)+")$"
pics.append(text(lt,(0,0)))
pics.append(circlepacking(f,bv))
graphics_array(pics).show(axes=False,aspect_ratio=1)
I have looked at the matplotlib home page. I can see that there is a class Figure and so on. Should I be attempting to use these since I am working in sage?
I have used metapost and tikz in the past but not matlab.
P.S. I tried g=DiGraph() g.plot? and was directed to a file decorators.py
Last thing first: the entry for g.plot? is still correct, right? There is a pretty long entry there. There is probably a default input decorator involved which accounts for the incorrect file.
It would be really helpful to see some (toy) examples of what you are saying; that would make it easier to see whether you could improve it. But it certainly sounds like you should use the graph plotting procedures, which allow a lot of customization of placement of vertices and so forth.
Which graph plotting procedures are you referring to?