#21008 closed defect (fixed)
Allow nonascii labels in graph vertices (at least for plotting)
Reported by:  kcrisman  Owned by:  

Priority:  minor  Milestone:  sage7.3 
Component:  graph theory  Keywords:  
Cc:  Merged in:  
Authors:  Frédéric Chapoton  Reviewers:  Jori Mäntysalo 
Report Upstream:  N/A  Work issues:  
Branch:  e6523a1 (Commits)  Commit:  
Dependencies:  Stopgaps: 
Change History (18)
comment:1 Changed 4 years ago by
 Branch set to u/chapoton/21008
 Commit set to 6b6633c2dca7b0e1b8bd9917c95013e9031cf931
 Status changed from new to needs_review
comment:2 Changed 4 years ago by
 Reviewers set to Jori Mäntysalo
Mäntysalo can review this patch made by Frédéric.
comment:3 Changed 4 years ago by
I take it that would create some selfreferential directed graph of review with Unicode vertices :) just make sure it doesn't break any current graph plots!
comment:4 Changed 4 years ago by
Documentation doesn't build with this fix. See #13161 for similar problem.
Also, the Russian character displays as a square box on Mac OS X El Capitan. Local Unicode fonts do not get incorporated into matplotlib output. Shouldn't there be some simple way to use local fonts?
comment:5 Changed 4 years ago by
 Commit changed from 6b6633c2dca7b0e1b8bd9917c95013e9031cf931 to 7d03de3d417c4f450eb2c05b460c702d97f4f7e8
Branch pushed to git repo; I updated commit sha1. New commits:
7d03de3  trac 21008 utf8 encoding of file, plus nicer doctest

comment:6 followup: ↓ 8 Changed 4 years ago by
I don't understand. This works:
DiGraph({u'Mäntysalo':[u'Frédéric']}).plot()
but this does not:
D = DiGraph() D.add_edge(u'Mäntysalo', u'Frédéric') G.show()
comment:7 Changed 4 years ago by
 Status changed from needs_review to needs_work
Also src/sage/combinat/posets/posets.py
fails some test.
comment:8 in reply to: ↑ 6 Changed 4 years ago by
Replying to jmantysalo:
I don't understand. This works:
DiGraph({u'Mäntysalo':[u'Frédéric']}).plot()but this does not:
D = DiGraph() D.add_edge(u'Mäntysalo', u'Frédéric') G.show()
It should be D.show(), and it works for me.
comment:9 Changed 4 years ago by
 Commit changed from 7d03de3d417c4f450eb2c05b460c702d97f4f7e8 to e6523a1bddb868d47353f1f5234f24f183d74865
Branch pushed to git repo; I updated commit sha1. New commits:
e6523a1  trac 21008 fixing doctests in posets

comment:10 Changed 4 years ago by
 Status changed from needs_work to needs_review
comment:11 Changed 4 years ago by
 Status changed from needs_review to positive_review
My mistake. Now it works and also
D = DiGraph() D.add_edge(u'Frédéric', 'review', u'Mäntysalo') D.show(edge_labels=True)
works.
comment:12 Changed 4 years ago by
Do we want all vertex labels to be unicode automatically? (I'm not sure if that is what is happening with the changed doctest in posets.)
comment:13 Changed 4 years ago by
labels are converted to unicode in the plot, not in the graphs themselves.
comment:14 Changed 4 years ago by
Got it, thanks.
comment:15 Changed 4 years ago by
 Branch changed from u/chapoton/21008 to e6523a1bddb868d47353f1f5234f24f183d74865
 Resolution set to fixed
 Status changed from positive_review to closed
comment:16 Changed 3 years ago by
 Commit e6523a1bddb868d47353f1f5234f24f183d74865 deleted
On my machine (7.4.beta1), the example given in the ticket description does not work:
sage: Graph({'Б':[1,2]}).plot() ... UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
Probably due to:
sage: type('Б') <type 'str'> sage: type(u'Б') <type 'unicode'>
comment:17 Changed 3 years ago by
you forgot the u
. Ths is not an ascii string. As long as nobody cares about py3, we have to add a u
for unicode strings.
comment:18 Changed 3 years ago by
The point was that 'Б' is a valid string (through not unicode), which is not handled by plot. If it will automatically be fixed by Python 3, it is probably better not to add artificial noise into the source code.
Here is a tentative. Sometimes the character is not available in the usual font. At least this works for the more common utf8 characters.
http://stackoverflow.com/questions/10960463/nonasciicharactersinmatplotlib
New commits:
trac 21008 allow unicode labels in graphs