How to get native Wolfram plots #340
Replies: 7 comments 7 replies
-
Yes. There is a terminal in the command palette, where you can select There is a better way to do it. firstly launch at least 1 LaunchKernels[1] then you With[{
p = Plot[x, {x,0,1}],
dir = FileNameJoin[{$TemporaryDirectory, "test.png"}]
},
ParallelSubmitAsync[Export[dir, p]] // WaitAll
];
Import[%]
boom ;) ![]() I should have been told you early about it. This idea just came to my mind, I have forgotten that they are absolutely "clean". |
Beta Was this translation helpful? Give feedback.
-
You are truly a genius! Thanks!Gani-Sent from my iPhoneOn Jan 25, 2025, at 12:41 PM, Kirill Vasin ***@***.***> wrote:
Yes. There is a terminal in the command palette, where you can select Master Kernel. It is basically a frontend server, which is not affected by WLJS Packages. However, it does not have an easy access to your notebook data (unless you export the data you want to plot and then import it using master kernel to rasterize it...)
There is a better way to do it.
You can use parallel kernels (are not affected by WLJS packages)
firstly launch at least 1
LaunchKernels[1]
then you ParallelSubmitAsync (see docs)
With[{
p = Plot[x, {x,0,1}],
dir = FileNameJoin[{$TemporaryDirectory, "test.png"}]
},
ParallelSubmitAsync[Export[dir, p]] // WaitAll
];
Import[%]
boom ;)
Screenshot.2025-01-25.at.21.35.33.png (view on web)
I should have been told you early about it. This idea just came to my mind, I have forgotten that they are absolutely "clean".
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Never mind. With the latest version, it works fine. Thx -- |
Beta Was this translation helpful? Give feedback.
-
I tried to make the above into a module for repeated plots which works but I get an error message like so... ![]() Any suggestions on how to fix it? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
A bulky filesize is an effect of the combination of two things (writing just for other contributors as well)
In the future we will definitely move to a fully binary data format, but when, it is hard to say (could be somewhere in 2025). Anyway, I have a solution for your case using good-old HTML ;) embedImage[i_Image] := With[{uid = CreateUUID[]}, With[{
path = FileNameJoin[{NotebookDirectory[], "images", uid<>".png"}]
},
Export[path, i];
HTMLView[StringTemplate["<img src=\"/images/``.png\"/>"][uid]]
] ] or in order not to pollute that folder with many images (if you reevaluate many times the same cell), one can use cell-id as a filename embedImage[i_Image] := With[{uid = EvaluationCell[]//First}, With[{
path = FileNameJoin[{NotebookDirectory[], "images", uid<>".png"}]
},
Export[path, i];
HTMLView[StringTemplate["<img src=\"/images/``.png?nocache=``\"/>"][uid, RandomInteger[999999999]]]
] ] this odd thing here Then if you want to share this notebook with someone, you can compress and embed all project files (in the folder of the notebook) into the notebook using Embed files method and then save it. If someone opens (or you, if you restart an app and open this notebook again) it it will self extract all files and reduce its size back to normal (1 way process). Hope it helps as a temporal solution. Best, |
Beta Was this translation helpful? Give feedback.
-
#344 planned |
Beta Was this translation helpful? Give feedback.
-
I miss the ability to get high quality native Wolfram plots like before (e.g, Export["plt.png",Plot[Sin[x],{x,0,Pi}]]; Import["plt.png"]). This could sidestep many of the missing features of the WLJS Plot function. I was wondering if I could run this through a command line accessible through WLJS and then import the plot. That would be awesome addition because there are just too many nooks and crannies to fix all issues otherwise.
Thx!
Gani -
Beta Was this translation helpful? Give feedback.
All reactions