Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-ascii labels in graph vertices (at least for plotting) #21008

Closed
kcrisman opened this issue Jul 12, 2016 · 24 comments
Closed

Allow non-ascii labels in graph vertices (at least for plotting) #21008

kcrisman opened this issue Jul 12, 2016 · 24 comments

Comments

@kcrisman
Copy link
Member

Apparently graph vertex labels have to be ASCII.

Graph({'Б':[1,2]}).plot()

See here and the duplicate here.

Component: graph theory

Author: Frédéric Chapoton

Branch: e6523a1

Reviewer: Jori Mäntysalo

Issue created by migration from https://trac.sagemath.org/ticket/21008

@kcrisman kcrisman added this to the sage-7.3 milestone Jul 12, 2016
@fchapoton
Copy link
Contributor

comment:1

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/non-ascii-characters-in-matplotlib


New commits:

6b6633ctrac 21008 allow unicode labels in graphs

@fchapoton
Copy link
Contributor

Branch: u/chapoton/21008

@fchapoton
Copy link
Contributor

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor

Commit: 6b6633c

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 12, 2016

comment:2

Mäntysalo can review this patch made by Frédéric.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 12, 2016

Reviewer: Jori Mäntysalo

@kcrisman
Copy link
Member Author

comment:3

I take it that would create some self-referential directed graph of review with Unicode vertices :-) just make sure it doesn't break any current graph plots!

@paulmasson
Copy link
Mannequin

paulmasson mannequin commented Jul 13, 2016

comment:4

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?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 13, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

7d03de3trac 21008 utf8 encoding of file, plus nicer doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 13, 2016

Changed commit from 6b6633c to 7d03de3

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 13, 2016

comment:6

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()

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 13, 2016

comment:7

Also src/sage/combinat/posets/posets.py fails some test.

@jm58660 jm58660 mannequin added s: needs work and removed s: needs review labels Jul 13, 2016
@fchapoton
Copy link
Contributor

comment:8

Replying to @jm58660:

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 13, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

e6523a1trac 21008 fixing doctests in posets

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 13, 2016

Changed commit from 7d03de3 to e6523a1

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 13, 2016

comment:11

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.

@kcrisman
Copy link
Member Author

comment:12

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.)

@fchapoton
Copy link
Contributor

comment:13

labels are converted to unicode in the plot, not in the graphs themselves.

@kcrisman
Copy link
Member Author

comment:14

Got it, thanks.

@vbraun
Copy link
Member

vbraun commented Jul 13, 2016

Changed branch from u/chapoton/21008 to e6523a1

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Aug 24, 2016

comment:16

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'>

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Aug 24, 2016

Changed commit from e6523a1 to none

@fchapoton
Copy link
Contributor

comment:17

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.

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Aug 24, 2016

comment:18

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants