Re: Strange behaviour when generating SVG files for (combinatorial) graphs

81 views
Skip to first unread message

Jason Grout

unread,
Nov 28, 2012, 1:26:24 AM11/28/12
to sage-s...@googlegroups.com
On 11/27/12 11:43 PM, Rog�rio Brito wrote:
> Hi there.
>
> I was just trying to get my feet wet with Sage by generating some SVG files of graphs for use with my LaTeX documents, but I noticed a problem:
>
> In the following session, with Sage 5.4.1 (actually, sage-5.4.1-linux-32bit-ubuntu_12.04.1_lts-i686-Linux) running on a Debian sid machine, I get a strange error:
>
> g = graphs.PetersenGraph()
> g.plot().save('petersen.png') # generated OK
> g.plot().save('petersen.pdf') # also generated OK
> g.plot().save('petersen.svg') # not OK
>
> In the case of the SVG file, the edges of the graph are OK, as with the PNG and PDF format (when viewed with Gnome's eog), but all the vertices are collapsed on the top left corner of the figure.
>
> BTW, my original intention was to generate some drawings of graphs with Sage so that I could shift back and forth between SVG and tikz (via Inkscape), once they are created by Sage, but that strategy didn't work. :(
>
> Is this a known bug?

Can you try opening the svg file up in inkscape? It may be a problem
with eog. When I open the file in inkscape, the graph looks great.
When I try to view the svg in chrome, the vertices look fine, but 4
edges are missing. Those edges appear just fine in inkscape.

Thanks,

Jason



P Purkayastha

unread,
Nov 28, 2012, 2:25:36 AM11/28/12
to sage-s...@googlegroups.com
On 11/28/2012 01:43 PM, Rog�rio Brito wrote:
> Hi there.
>
> I was just trying to get my feet wet with Sage by generating some SVG files of graphs for use with my LaTeX documents, but I noticed a problem:
>
> In the following session, with Sage 5.4.1 (actually, sage-5.4.1-linux-32bit-ubuntu_12.04.1_lts-i686-Linux) running on a Debian sid machine, I get a strange error:
>
> g = graphs.PetersenGraph()
> g.plot().save('petersen.png') # generated OK
> g.plot().save('petersen.pdf') # also generated OK
> g.plot().save('petersen.svg') # not OK
>

The svg graph shows up fine when viewed in my file browser (as a
thumbnail), when viewed using display (from imagemagick), when viewed
using feh (uses imlib2), and when viewed using inkscape. So, I suspect
it is a problem with your viewer.


Rogério Brito

unread,
Nov 28, 2012, 3:28:35 AM11/28/12
to sage-s...@googlegroups.com
Hi, Jason.

On Wed, Nov 28, 2012 at 4:26 AM, Jason Grout
<jason...@creativetrax.com> wrote:
> On 11/27/12 11:43 PM, Rogério Brito wrote:
>> g = graphs.PetersenGraph()
>> g.plot().save('petersen.png') # generated OK
>> g.plot().save('petersen.pdf') # also generated OK
>> g.plot().save('petersen.svg') # not OK
>
> Can you try opening the svg file up in inkscape? It may be a problem with
> eog.

Actually, I tried opening the svg file in inkscape and the result was
worse (no graph appearing at all).

Here is what I see, in different programs (the original svg file
generated above and its visualizations with many programs):

http://www.ime.usp.br/~rbrito/petersen-graph/

> When I open the file in inkscape, the graph looks great. When I try to
> view the svg in chrome, the vertices look fine, but 4 edges are missing.
> Those edges appear just fine in inkscape.

If I try to see the file in a brower (no matter if try the graph in a
webkit-based browser or in a gecko-based browser), I don't see the
edges, as you can attest above.


Thank you very much for your feedback,

--
Rogério Brito : rbrito@{ime.usp.br,gmail.com} : GPG key 4096R/BCFCAAAA
http://rb.doesntexist.org/blog : Projects : https://github.com/rbrito/
DebianQA: http://qa.debian.org/developer.php?login=rbrito%40ime.usp.br

Rogério Brito

unread,
Nov 28, 2012, 3:38:54 AM11/28/12
to sage-s...@googlegroups.com
Hi,

On Wed, Nov 28, 2012 at 5:25 AM, P Purkayastha <ppu...@gmail.com> wrote:
> On 11/28/2012 01:43 PM, Rogério Brito wrote:
>> g = graphs.PetersenGraph()
>> g.plot().save('petersen.png') # generated OK
>> g.plot().save('petersen.pdf') # also generated OK
>> g.plot().save('petersen.svg') # not OK
>
> The svg graph shows up fine when viewed in my file browser (as a thumbnail),
> when viewed using display (from imagemagick),

I get the same results when I try to see the file with nautilus (my
current file browser) or with display/convert from imagemagick. I may
try graphicsmagick to see if there is any difference, but I'm not that
hopeful.

> when viewed using feh (uses imlib2),

Just tried feh and it delegates seeing the file to chromium, with a
message on the terminal saying:

feh WARNING: ./petersen.svg - No Imlib2 loader for that file format

> and when viewed using inkscape.

I posted what I see at:

http://www.ime.usp.br/~rbrito/petersen-graph/

I would be thankful for any help.

> So, I suspect it is a problem with your viewer.

I wouldn't rule out anything. Just curious: if I understand it
correctly, the SVG file is generated with matplotlib. How can I try
the equivalent call above to matplotlib directly?

Thanks for the help so far,

P Purkayastha

unread,
Nov 28, 2012, 3:58:28 AM11/28/12
to sage-s...@googlegroups.com
On 11/28/2012 04:38 PM, Rog�rio Brito wrote:
> Hi,
>
> On Wed, Nov 28, 2012 at 5:25 AM, P Purkayastha<ppu...@gmail.com> wrote:
>> On 11/28/2012 01:43 PM, Rog�rio Brito wrote:
>>> g = graphs.PetersenGraph()
>>> g.plot().save('petersen.png') # generated OK
>>> g.plot().save('petersen.pdf') # also generated OK
>>> g.plot().save('petersen.svg') # not OK
>>
>> The svg graph shows up fine when viewed in my file browser (as a thumbnail),
>> when viewed using display (from imagemagick),
>
> I get the same results when I try to see the file with nautilus (my
> current file browser) or with display/convert from imagemagick. I may
> try graphicsmagick to see if there is any difference, but I'm not that
> hopeful.
>
>> when viewed using feh (uses imlib2),
>
> Just tried feh and it delegates seeing the file to chromium, with a
> message on the terminal saying:
>
> feh WARNING: ./petersen.svg - No Imlib2 loader for that file format
>
>> and when viewed using inkscape.
>
> I posted what I see at:
>
> http://www.ime.usp.br/~rbrito/petersen-graph/
>
> I would be thankful for any help.
>
>> So, I suspect it is a problem with your viewer.
>
> I wouldn't rule out anything. Just curious: if I understand it
> correctly, the SVG file is generated with matplotlib. How can I try
> the equivalent call above to matplotlib directly?
>
> Thanks for the help so far,
>

Your svg file itself is corrupted. Can you check if you get the correct
svg figures if you plot using pyplot? Something like this:

import matplotlib.pyplot as plt
plt.plot(range(10), range(10), '-o')
plt.savefig('a.svg')

As for the actual matplotlib commands used, look at the commands used in
the source code:

p = graphs.PetersenGraph().plot()
p.save??

You can get the matplotlib object out of sage by doing
p = graphs.PetersenGraph().plot().matplotlib()

Jason Grout

unread,
Nov 28, 2012, 9:10:31 AM11/28/12
to sage-s...@googlegroups.com
On 11/28/12 2:28 AM, Rog�rio Brito wrote:
> Hi, Jason.
>
> On Wed, Nov 28, 2012 at 4:26 AM, Jason Grout
> <jason...@creativetrax.com> wrote:
>> On 11/27/12 11:43 PM, Rog�rio Brito wrote:
>>> g = graphs.PetersenGraph()
>>> g.plot().save('petersen.png') # generated OK
>>> g.plot().save('petersen.pdf') # also generated OK
>>> g.plot().save('petersen.svg') # not OK
>>
>> Can you try opening the svg file up in inkscape? It may be a problem with
>> eog.
>
> Actually, I tried opening the svg file in inkscape and the result was
> worse (no graph appearing at all).
>
> Here is what I see, in different programs (the original svg file
> generated above and its visualizations with many programs):
>
> http://www.ime.usp.br/~rbrito/petersen-graph/
>
>> When I open the file in inkscape, the graph looks great. When I try to
>> view the svg in chrome, the vertices look fine, but 4 edges are missing.
>> Those edges appear just fine in inkscape.
>
> If I try to see the file in a brower (no matter if try the graph in a
> webkit-based browser or in a gecko-based browser), I don't see the
> edges, as you can attest above.


Just to make sure it's not your Sage setup, can you try using the svg
file generated by:

http://aleph.sagemath.org/?q=0a6eed66-9356-48b3-8a7b-0a058beb5d73&lang=sage

When I click on the svg file in Firefox 15.0.1 on OS X 10.6.8, the graph
looks great.

Thanks,

Jason



Rogério Brito

unread,
Nov 28, 2012, 7:01:42 PM11/28/12
to sage-s...@googlegroups.com
Hi, Jason.

On Wed, Nov 28, 2012 at 12:10 PM, Jason Grout
<jason...@creativetrax.com> wrote:
> Just to make sure it's not your Sage setup, can you try using the svg file
> generated by:
>
> http://aleph.sagemath.org/?q=0a6eed66-9356-48b3-8a7b-0a058beb5d73&lang=sage
>
> When I click on the svg file in Firefox 15.0.1 on OS X 10.6.8, the graph
> looks great.

The generated graph on that page looks great, without any of the
distortions that I see with my local copy of sage. So, we have
possibly (among other things):

* A bad interaction of my Debian system and the provided build.
* Some possible bug in the matplotlib or anything called by it in the
provided build?

Thanks for helping isolate the problem,
Reply all
Reply to author
Forward
0 new messages