ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Mar 2021 00:17:54 +0100Plot "color_by_label" produces SQUARED number of lines in digraphhttps://ask.sagemath.org/question/56324/plot-color_by_label-produces-squared-number-of-lines-in-digraph/I bumped into this unusual behavior and am not sure how to fix it.
When I add `color_by_label` for plotting a digraph I get the correct
number SQUARED of lines appearing in the digraph. Is this an error
in SageMath or is there a workaround? All monochrome lines
do not work for my application.
This is my code sample:
stnc = 'ABCCCCDABCDABCDA'
g = DiGraph({}, loops=True, multiedges=True)
for a, b in [(stnc[i], stnc[i + 1]) for i in range(len(stnc) - 1)]:
g.add_edge(a, b, b)
sage: g.edges()
[('A', 'B', 'B'), ('A', 'B', 'B'), ('A', 'B', 'B'),
('B', 'C', 'C'), ('B', 'C', 'C'), ('B', 'C', 'C'),
('C', 'C', 'C'), ('C', 'C', 'C'), ('C', 'C', 'C'),
('C', 'D', 'D'), ('C', 'D', 'D'), ('C', 'D', 'D'),
('D', 'A', 'A'), ('D', 'A', 'A'), ('D', 'A', 'A')]
# This produces the correct number of lines SQUARED
g.plot(color_by_label=True, edge_style='solid', layout='circular').show(figsize=(8, 8))
# Correct number of lines but monochrome
g.plot(layout='circular').show(figsize=(8, 8))
![Incorrect edge multiplicity for multidigraph with color_by_label](/upfiles/16164608644236614.png)
Each edge should have multiplicity 3.
In the plot with color edges, each has multiplicity 9.
The plot with no colors has correct multiplicity 3 for each edge.JJTue, 23 Mar 2021 00:17:54 +0100https://ask.sagemath.org/question/56324/How to make pygraphviz and sage compatible?https://ask.sagemath.org/question/31070/how-to-make-pygraphviz-and-sage-compatible/ Hi,
I would like sage to help me when I am working with (un)directed graphs and quivers, and so on. After having played around with various possibilities, I would like to convert some stuff into a string and then let sage print something like a .ps - file that contains an image from dot (or something similar to this).
> Unfortunately, I came across the following issue(s) and have no idea what to do now. With the sage version I installed, there is python 2.x as a delivered package. But it seems that sage complains about python3, what doesn't make sense to me.
Could you help me understand and solve the following:
boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ ./sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.9, Release Date: 2015-10-10 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import networkx as nx
sage: import matplotlib.pyplot as plt
sage: import matplotlib.image as mpimg
sage: from cStringIO import StringIO
sage: g = nx.dodecahedral_graph()
sage: d = nx.to_pydot(g)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-0d33c400a5cf> in <module>()
----> 1 d = nx.to_pydot(g)
AttributeError: 'module' object has no attribute 'to_pydot'
sage: d = nx.to_agraph(g)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-d9254026fb59> in <module>()
----> 1 d = nx.to_agraph(g)
/home/boehmler/Schreibtisch/bb/sage-6.9-x86_64-Linux/local/lib/python/networkx/drawing/nx_agraph.pyc in
to_agraph(N)
132 raise ImportError('requires pygraphviz ',
133 'http://networkx.lanl.gov/pygraphviz ',
--> 134 '(not available for Python3)')
135 directed=N.is_directed()
136 strict=N.number_of_selfloops()==0 and not N.is_multigraph()
ImportError: ('requires pygraphviz ', 'http://networkx.lanl.gov/pygraphviz ', '(not available for Python3)')
sage:
Exiting Sage (CPU time 0m3.33s, Wall time 56m28.80s).
After typing
boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ sudo -H pip install pygraphviz
I get the message
Wall -Wstrict-prototypes -fPIC -I/usr/include/graphviz -I/usr/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.linux-x86_64-2.7/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:130:21: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden
# include <Python.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-6yZh3l/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a6o8Fg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-6yZh3l/pygraphviz
in the end. I would be grateful for any hints how to solve / fix this.
Thanks for the help!
BernThu, 26 Nov 2015 03:42:50 +0100https://ask.sagemath.org/question/31070/Orientation of poset plot in Sage 6.3 vs 6.4https://ask.sagemath.org/question/25192/orientation-of-poset-plot-in-sage-63-vs-64/In older versions of Sage (6.3 and below), plotting a poset (or an acyclic graph with layout = "acyclic") gives a directed graph with arrows pointing up.
However, it seems like in Sage 6.4, the arrows now point down (and the bottom element appears at the top).
Is this a bug? Or are there any options I can tweak to reverse the orientation? I would expect the "correct" behaviour to be the one with the arrows pointing up; the Sage reference on [layout_acyclic](http://www.sagemath.org/doc/reference/graphs/sage/graphs/digraph.html#sage.graphs.digraph.DiGraph.layout_acyclic) seems to agree.
(I noticed the discrepancy while running Sage 6.3 on the [Sage Cell Server](http://sagecell.sagemath.org/) and Sage 6.4 on [Sagemath Cloud](https://cloud.sagemath.com/))
Here's some code you can try:
Poset({0:[2],1:[2],2:[]}).show()ZeWed, 10 Dec 2014 10:07:32 +0100https://ask.sagemath.org/question/25192/plot digraph use adjacency matrixhttps://ask.sagemath.org/question/9775/plot-digraph-use-adjacency-matrix/Hi everyone, I got a question here, and I have been trying to debug it for past week, still can't get it sorted out, can anyone please help me? Thanks heaps.
I have a file as my data (will paste at the bottom), basically the vertices are all binary strings with directed edges named "a" or "b", or "c". For example, if in my data, there is line says (0000, a, 1000), that means there is an edge from vertex 0000 to 1000 named a. Similarly, if I have (0000, b, 0000), means there is a self-loop from 0000 to it self named b. So there can be more than one self-loops sometimes.
Now I have written the function digraph as below:
def digraph(n, filename):
f = open(filename, 'r')
W = Words('01', length=n)
S = [str(w) for w in W]
M = zero_matrix(ZZ, 2^n)
f.readline()
for c in f:
c = c[1:-2]
s1, g, s2 = c.split(', ')
i = S.index('word: ' + s1)
j = S.index('word: ' + s2)
M[i,j] = 1
f.close()
return DiGraph(M, vertex_labels=S, loops = True, implementation="c_graph")
So the idea should be pretty simple, create list of words with all binary strings length 4, then search where my data the words are allocated in the list, then assign value to 1 to the entries of my original zero matrix.
But I keep getting error message says change a copy of the matrix instead, I tried to make a copy(M), but still doesn't work, then it says something else like "need more than 1 value unpack" etc.
I really need a hand on this please, can anybody help me please? Also, I can't understand why it is exactly same code, but used to run very well on someone else's linux computer two months ago, and I didn't change anything but it just wouldn't run here and the error messages seem like syntax error.
Here are my data as below
(0000, a, 1000)
(0000, b, 0000)
(0000, c, 0000)
(0001, a, 1001)
(0001, b, 0001)
(0001, c, 0001)
(0010, a, 1010)
(0010, b, 0010)
(0010, c, 0010)
(0011, a, 1011)
(0011, b, 0011)
(0011, c, 0011)
(0100, a, 1110)
(0100, b, 0100)
(0100, c, 0100)
(0101, a, 1111)
(0101, b, 0101)
(0101, c, 0101)
(0110, a, 1100)
(0110, b, 0111)
(0110, c, 0111)
(0111, a, 1101)
(0111, b, 0110)
(0111, c, 0110)
(1000, a, 0000)
(1000, b, 1000)
(1000, c, 1100)
(1001, a, 0001)
(1001, b, 1001)
(1001, c, 1101)
(1010, a, 0010)
(1010, b, 1010)
(1010, c, 1111)
(1011, a, 0011)
(1011, b, 1011)
(1011, c, 1110)
(1100, a, 0110)
(1100, b, 1110)
(1100, c, 1000)
(1101, a, 0111)
(1101, b, 1111)
(1101, c, 1001)
(1110, a, 0100)
(1110, b, 1100)
(1110, c, 1011)
(1111, a, 0101)
(1111, b, 1101)
(1111, c, 1010)
tsangWed, 06 Feb 2013 00:47:34 +0100https://ask.sagemath.org/question/9775/Font size for edge labelhttps://ask.sagemath.org/question/8233/font-size-for-edge-label/Simple example:
d = DiGraph()
d.add_edge(1, 2, '$a_0$')
d.plot(edge_labels=True)
gives me extremely small edge label 'a0', is it possible to increase font size for all edge labels?EugeneSun, 17 Jul 2011 09:44:41 +0200https://ask.sagemath.org/question/8233/Best way to plot graphhttps://ask.sagemath.org/question/8226/best-way-to-plot-graph/Hello!
Could you pleas advise me the best way to plot graph with cycles and make it looks like tree? Here is the sample picture of result I'd like to have:
![image description](http://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Artificial_neural_network.svg/350px-Artificial_neural_network.svg.png)
Plot on this pictures have 'layers', is there any chance to get something like this in Sage? I tried this:
t = DiGraph()
t.add_edge((0,1))
t.add_edge((0,2))
t.add_edge((0,3))
t.add_edge((0,4))
t.add_edge((4,9))
t.add_edge((3,9))
t.add_edge((2,9))
t.add_edge((1,9))
t.plot()
but the [result](http://img17.imageshack.us/i/sage0.png/) is far from desired.
Thanks.
EugeneThu, 14 Jul 2011 17:23:01 +0200https://ask.sagemath.org/question/8226/