Ask Your Question

Revision history [back]

Mathematica graphics in a sage notebook

Is there an easy way to get Mathematica graphics into a sage notebook?

I have a notebook where I want to compare the Mathematica way of doing things and the related graphics to the sage way and its graphics. The naive ways of doing it do not work:


just produces




returns the InputForm of the graphics, i.e.,

Graphics[{{{}, {}, {Hue[0.67, 0.6, 0.6], Line[{<<long list of points>>}], 
         <<some graphics options>>]

There's three work-arounds I can currently think of.

  1. Export the graphics from Mathematica using: Export["file.png", graphics] and import it back into sage - but I couldn't find an image import function in sage...

  2. Use the JavaGraphics Mathematica package: So

    because code formatting was failing me

    but this puts the graphics object in a separate window (not in the sage notebook).

  3. Extract the graphics data and feed it into a sage plotting function, e.g.

    list_plot(mathematica('Plot[Sin[x], {x, -4, 4}][[1, 1, 3, 2, 1]]').sage(), plotjoined = true)

which does what I want, but is a little cumbersome - especially for more complicated graphics.