Mathematica Asked by wuyudi on March 24, 2021
I have following code, which can run in notebook.
CreateDialog[
ExpressionCell[
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
SphericalRegion -> True], Selectable -> True, Deployed -> False]]
It will pop out a window.
I tried to run it in .wls
file, but it said that
FrontEndObject::notavail:
A front end is not available; certain operations require a front end.
So I add UsingFrontEnd
, but still get nothing.
UsingFrontEnd[
CreateDialog[
ExpressionCell[
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
SphericalRegion -> True], Selectable -> True, Deployed -> False]]
]
How to solve this problem?
Well, CreateDialog
just cannot work.
However, e.g. on Linux it is easy to let the image being popped up by the wls script, supposed that ImageMagick is installed and you can use the display function:
This is the script test.wls
#!/usr/bin/env wolframscript
Echo @ ("starting " <> $Version <> " in " <> Directory[]);
(* generating the plot *)
plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, SphericalRegion -> True];
(* exporting it to, e.g. JPG, just works: *)
file = Export["sinPlot.jpg", plot];
(* this displays the file name *)
Echo @ file;
(* one possibility to open the file from within this script *)
Run["/usr/bin/display " <> file];
On Windows, with ImageMagick installed as usual:
#!/usr/bin/env wolframscript
plot = Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2},SphericalRegion->True];
file = Export["sinPlot.jpg",plot]
fName = FileNameJoin[{Directory[],file}]
RunProcess[{"cmd","/c",""C:Program FilesImageMagickimdisplay.exe"",fName}]
Correct answer by Rolf Mertig on March 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP