I'm looking for a remote machine to generate a Plot, and save the file so that I can import it and manipulate it as a standard Mathematica object later. How do you export the object as such? I can export to a PDF, but not to a data form where I can later import and manipulate.

A sketch of the workflow I would like: On remote machine:

plot = Plot[Sin[x], {x, 0, 10}, ImageSize -> Small];
Export["/path/file.ext", plot]

Transfer the file, then on local machine import and manipulate:

plot = Import["/path/file.ext"];
Show[plot, ImageSize -> Large]

I'm not looking to make a Table of values because I am leaving Mathematica to optimise the plot sampling (function evaluation is very expensive). I don't mind extracting the values it created in order to recreate the Plot, but I also don't know how to do that. Also, the remote machine is running in command-line mode.

  • $\begingroup$ Try usingDumpSave and Get $\endgroup$ – m_goldberg Sep 10 '16 at 16:27
  • $\begingroup$ @m_goldberg, the Get call gives me $Failed. Both computers run Linux, but the remote machine has version 11, whereas the local has version 10.2, maybe that might be causing it? $\endgroup$ – bjorne Sep 10 '16 at 16:40
  • $\begingroup$ Is there any way to get more information from the error? $\endgroup$ – bjorne Sep 10 '16 at 16:51
  • $\begingroup$ My bad, DumpSave can be platform and version dependent. Mainly intended for use on a single machine, not for transferring objects between systems running different versions of Mathematica. $\endgroup$ – m_goldberg Sep 10 '16 at 16:53
plot = Plot[Sin[x], {x, 0, 10}, ImageSize -> Small];

pts = Cases[plot, Line[pts_] :> pts, Infinity][[1]];

Export["pts.csv", pts];

At the second machine

pts2 = Import["pts.csv"];

ListLinePlot[pts2, ImageSize -> Large]

I don't have a multi-system environment to test this with, but you might try

Put[plot, FileNameJoin[{..., "plot.m"}]]

on one system and

Get[FileNameJoin[{..., "plot.m"}]]

You need to replace ... with the proper network path for the file, of course.

  • $\begingroup$ Thanks for this. The Put command on the remote machine returns Put::stream: -Graphics- is not a string, SocketObject, InputStream[ ], or OutputStream[ ]. $\endgroup$ – bjorne Sep 10 '16 at 17:12
  • $\begingroup$ @bjorne. Don't Put directly to the remote machine. Have Put write to your local machine. Transfer the file to the remote machine with a system utility, and then do the Get on the remote machine from the transferred file. $\endgroup$ – m_goldberg Sep 10 '16 at 18:54
  • $\begingroup$ That's what I was doing (but in the opposite direction, because I want the remote machine to do the heavy lifting, so it needs to do the Put). All Mathematica actions were local, and the file transfer was a system utility. $\endgroup$ – bjorne Sep 10 '16 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.