Any chance of having labels in Unicode?
dear all, I would like to use math symbols (such as ∈, ⊆ and ∡) and Greek letters into labels (vertex properties and edge properties), so that they can appear in graph-tool-made or graphviz-made graphs. How can I use graph-tool in a Unicode-compliant way? thanks in advance Yannis H. -- ------------------------------------------------------- Yannis Haralambous Professor Institut Mines-Télécom, Télécom Bretagne Computer Science Department UMR CNRS 6285 Lab-STICC Technopôle Brest Iroise CS 83818, 29238 Brest Cedex 3, France Email: yannis.haralambous@telecom-bretagne.eu Internet: http://perso.telecom-bretagne.eu/yannisharalambous/ ICBM address: 48°21'31.57"N 4°34'16.76"W Twitter: y_haralambous ------------------------------------------------------- ...the ball I threw while playing in the park has not yet reached the ground (Dylan Thomas) Es gab eine Zeit, wo ich nur ungern über Schubert sprechen, nur Nächtens den Bäumen und Sternen von ihm vorerzählen mögen. (Robert Schumann)
On 28.10.2015 15:35, Yannis Haralambous wrote:
dear all,
I would like to use math symbols (such as ∈, ⊆ and ∡) and Greek letters into labels (vertex properties and edge properties), so that they can appear in graph-tool-made or graphviz-made graphs.
How can I use graph-tool in a Unicode-compliant way?
It should work out of the box. You just need to use a font family that has the necessary glyphs. For instance, for me the following works: graph_draw(g, vertex_text="∈", vertex_font_family="Bitstream Vera Sans") Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
When I attempt to use a ∈ in a label, I get the following error message: File "apply-rules.py", line 25 SyntaxError: Non-ASCII character '\xe2' in file apply-rules.py on line 25, but no encoding declared; see for details When I include # coding=utf-8 at the beginning, and when I use u"∈" in the code then I get the following message: Traceback (most recent call last): File "apply-rules.py", line 474, in <module> execfile("rules.py") File "rules.py", line 13, in <module> signature=['204:6', '20456:4', '2045654:4', '45654:2', '456:2', '654:2', '2:3', '4:3', '6:1'] File "apply-rules.py", line 293, in apply_edge_rule r=att_edge(q,KNOWN[ms[0][0]],KNOWN[ms[0][5]],globals()[ms[0][3]]) File "apply-rules.py", line 352, in att_edge g.ep['labele'][res]=str(g.vp['labelv'][a])+"_"+EDGE_LABEL[val]+"_"+str(g.vp['labelv'][b]) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 490, in __setitem__ self.__map[key] = self.__convert(v) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 254, in convert return vtype(val) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2208' in position 3: ordinal not in range(128) So the problem is not yet how to make the symbol appear in graphviz output, but how to make the Python code run…
Le 28 oct. 2015 à 15:44, Tiago de Paula Peixoto <tiago@skewed.de> a écrit :
On 28.10.2015 15:35, Yannis Haralambous wrote:
dear all,
I would like to use math symbols (such as ∈, ⊆ and ∡) and Greek letters into labels (vertex properties and edge properties), so that they can appear in graph-tool-made or graphviz-made graphs.
How can I use graph-tool in a Unicode-compliant way?
It should work out of the box. You just need to use a font family that has the necessary glyphs. For instance, for me the following works:
graph_draw(g, vertex_text="∈", vertex_font_family="Bitstream Vera Sans")
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
-- ------------------------------------------------------- Yannis Haralambous Professor Institut Mines-Télécom, Télécom Bretagne Computer Science Department UMR CNRS 6285 Lab-STICC Technopôle Brest Iroise CS 83818, 29238 Brest Cedex 3, France Email: yannis.haralambous@telecom-bretagne.eu Internet: http://perso.telecom-bretagne.eu/yannisharalambous/ ICBM address: 48°21'31.57"N 4°34'16.76"W Twitter: y_haralambous ------------------------------------------------------- ...the ball I threw while playing in the park has not yet reached the ground (Dylan Thomas) Es gab eine Zeit, wo ich nur ungern über Schubert sprechen, nur Nächtens den Bäumen und Sternen von ihm vorerzählen mögen. (Robert Schumann)
On 28.10.2015 15:52, Yannis Haralambous wrote:
So the problem is not yet how to make the symbol appear in graphviz output, but how to make the Python code run…
Well, you should really read Python's documentation: https://docs.python.org/2/howto/unicode.html in short you should start your script with: #!/usr/bin/env python # -*- coding: utf-8 -*- example = u'abcdé' (I'm assuming you are using python 2. With python 3 it is simpler, since it accepts utf-8 by default.) Best, Tiago Ps. Note that graph_draw() *does not* use graphviz! -- Tiago de Paula Peixoto <tiago@skewed.de>
That is exactly what I did: # -*- coding: utf-8 -*- and then EDGE_LABEL=[u'∈'] and the script file stored in UTF-8 without BOM. And here is the error I got: Traceback (most recent call last): File "apply-rules.py", line 473, in <module> execfile("rules.py") File "rules.py", line 13, in <module> signature=['204:6', '20456:4', '2045654:4', '45654:2', '456:2', '654:2', '2:3', '4:3', '6:1'] File "apply-rules.py", line 292, in apply_edge_rule r=att_edge(q,KNOWN[ms[0][0]],KNOWN[ms[0][5]],globals()[ms[0][3]]) File "apply-rules.py", line 351, in att_edge g.ep['labele'][res]=str(g.vp['labelv'][a])+"_"+EDGE_LABEL[val]+"_"+str(g.vp['labelv'][b]) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 490, in __setitem__ self.__map[key] = self.__convert(v) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 254, in convert return vtype(val) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2208' in position 3: ordinal not in range(128)
Le 28 oct. 2015 à 15:59, Tiago de Paula Peixoto <tiago@skewed.de> a écrit :
On 28.10.2015 15:52, Yannis Haralambous wrote:
So the problem is not yet how to make the symbol appear in graphviz output, but how to make the Python code run…
Well, you should really read Python's documentation:
https://docs.python.org/2/howto/unicode.html
in short you should start your script with:
#!/usr/bin/env python # -*- coding: utf-8 -*-
example = u'abcdé'
(I'm assuming you are using python 2. With python 3 it is simpler, since it accepts utf-8 by default.)
Best, Tiago
Ps. Note that graph_draw() *does not* use graphviz!
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
-- ------------------------------------------------------- Yannis Haralambous Professor Institut Mines-Télécom, Télécom Bretagne Computer Science Department UMR CNRS 6285 Lab-STICC Technopôle Brest Iroise CS 83818, 29238 Brest Cedex 3, France Email: yannis.haralambous@telecom-bretagne.eu Internet: http://perso.telecom-bretagne.eu/yannisharalambous/ ICBM address: 48°21'31.57"N 4°34'16.76"W Twitter: y_haralambous ------------------------------------------------------- ...the ball I threw while playing in the park has not yet reached the ground (Dylan Thomas) Es gab eine Zeit, wo ich nur ungern über Schubert sprechen, nur Nächtens den Bäumen und Sternen von ihm vorerzählen mögen. (Robert Schumann)
On 28.10.2015 16:05, Yannis Haralambous wrote:
That is exactly what I did:
# -*- coding: utf-8 -*-
and then
EDGE_LABEL=[u'∈']
and the script file stored in UTF-8 without BOM.
And here is the error I got:
Traceback (most recent call last): File "apply-rules.py", line 473, in <module> execfile("rules.py") File "rules.py", line 13, in <module> signature=['204:6', '20456:4', '2045654:4', '45654:2', '456:2', '654:2', '2:3', '4:3', '6:1'] File "apply-rules.py", line 292, in apply_edge_rule r=att_edge(q,KNOWN[ms[0][0]],KNOWN[ms[0][5]],globals()[ms[0][3]]) File "apply-rules.py", line 351, in att_edge g.ep['labele'][res]=str(g.vp['labelv'][a])+"_"+EDGE_LABEL[val]+"_"+str(g.vp['labelv'][b]) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 490, in __setitem__ self.__map[key] = self.__convert(v) File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 254, in convert return vtype(val) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2208' in position 3: ordinal not in range(128)
The function does not expect unicode objects, but rather simply strings. You should do simply: EDGE_LABEL=[u'∈'.encode("utf-8")] Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (3)
-
Tiago de Paula Peixoto -
Yannis Haralambous -
Yannis Haralambous