displaying a graph using Graphs.m2 ?

118 views
Skip to first unread message

David Eisenbud

unread,
Apr 28, 2021, 2:10:21 AM4/28/21
to Google
I have a program that generates combinatorial data that I'd like to look at as a sequence of graphs; thus I want to use M2, which produces the data, to write a laTeX or pdf file.The package Graphs.m2 seems to have most of the required pieces, but...

(in MacOS, after brew install graphviz, sudo easy_install dot2tex, and getting the emacs $PATH to include /usr/local/bin), and making a simple matrix M representing a graph, the command

displayGraph graph M

produces some output:
-- running: dot -Tjpg /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-1831-0/8.dot -o /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-1831-0/9.jpg
-- running: display /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-1831-0/9.jpg &

and then the error message:
i56 : sh: display: command not found

Question: how can I teach sh to use some display program?

Doug Torrance

unread,
Apr 28, 2021, 5:56:31 AM4/28/21
to Macaulay2
Through Macaulay 1.17, you can set the "JpgViewer" configuration option when loading the package to your image viewer of choice:

    loadPackage("Graphs", Configuration => {"JpgViewer" => "image-viewer-goes-here"})

Note that this has been deprecated in git, and beginning in Macaulay2 1.18, displayGraph will use the "show" function to view the image.

David Eisenbud

unread,
Apr 29, 2021, 1:37:36 AM4/29/21
to Google
Thanks! I got one step farther, but not to the goal: after

loadPackage("Graphs", Reload => true, Configuration => {"JpgViewer" => "/System/Applications/Preview.app/Contents/MacOS/Preview"})
G = graph matrix"1,1;1,1"
displayGraph G

I got an error message from Preview saying that it couldn't display the graph because "You don't have permission to view it."

suggestions?

thanks,

David
--
David Eisenbud, Director, 
Mathematical Sciences Research Institute
and Professor of Mathematics, 
University of California, Berkeley


--
You received this message because you are subscribed to the Google Groups "Macaulay2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macaulay2+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/macaulay2/2b6807f0-1f25-4ec7-bb58-5875692b1ce9n%40googlegroups.com.

Doug Torrance

unread,
Apr 29, 2021, 10:24:08 AM4/29/21
to Macaulay2
I'm not a Mac user, so this may be incorrect, but I'm pretty sure that "JpgViewer" => "open" should work.

Branden Stone

unread,
Apr 29, 2021, 4:20:55 PM4/29/21
to Macaulay2
I am not sure about viewing the graph with Graphs.m2, but you could use the Visualize package to do this. The code would look something like this. 

load"Visualize.m2"
G = graph({{1,2},{2,3},{3,4}})
openPort"8080"
H = visualize G

This should open up your browser to view the graph along a means to generate the tikz code.  When finished you can close the port with 

closePort()

I haven't used this package in a while so I hope it still works. You can find the documentation here: 


Best, 

Branden

David Eisenbud

unread,
May 1, 2021, 12:46:25 PM5/1/21
to Google
Alas, no: here's the output after
loadPackage("Graphs", Reload => true, Configuration => {"JpgViewer" => "open"})

 displayGraph G
-- running: dot -Tjpg /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-2018-0/2.dot -o /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-2018-0/3.jpg
-- running: display /var/folders/zc/cq00n_411yzbcst8ypb4bnqh0000gp/T/M2-2018-0/3.jpg &

i49 : sh: display: command not found

Cordially,

David
--
David Eisenbud, Director, 
Mathematical Sciences Research Institute
and Professor of Mathematics, 
University of California, Berkeley

Doug Torrance

unread,
May 3, 2021, 9:33:04 AM5/3/21
to Macaulay2
Hmm, that's puzzling.  The value of "JpgViewer" should be what's displayed after the second "running" comment:

i1 : loadPackage("Graphs", Configuration => {"JpgViewer" => "asdf"});

i2 : displayGraph completeGraph 5
-- running: dot -Tjpg /tmp/M2-1195728-0/0.dot -o /tmp/M2-1195728-0/1.jpg
-- running: asdf /tmp/M2-1195728-0/1.jpg &
sh: 1: asdf: not found

But that's not happening in your case (it still says "display" instead of "open").  One possible workaround would be to directly modify the graphs'JpgViewer string (which keeps track of the image viewer but isn't exported) directly:

i2 : debug Graphs

i3 : graphs'JpgViewer = "open"

o3 = open

i4 : displayGraph completeGraph 5
-- running: dot -Tjpg /tmp/M2-1198999-0/0.dot -o /tmp/M2-1198999-0/1.jpg
-- running: open /tmp/M2-1198999-0/1.jpg &

Doug



David Eisenbud

unread,
May 3, 2021, 12:20:20 PM5/3/21
to Macaulay2
That worked! -- thanks!
David

Reply all
Reply to author
Forward
0 new messages