Hot answers tagged

17

When you use the "Base64" you are encoding a particular file format. For Export calls the file format is inferred from the file name given, like Export["file.ext.b64", expr] uses the ext format. When used with ExportString, the format is chosen automatically. You can see here that the automatically chosen format is "String": ExportString["foobar中文", {"...


11

It is as easy as follows using low-level Notebook programming: outputCells = Cells[CellStyle -> "Output"]; cellsWithGraphics = Select[outputCells, ! FreeQ[NotebookRead[#], GraphicsBox] &]; MapIndexed[Export[ToString[#2[[1]]] <> ".png", #1] &, cellsWithGraphics] This solution assumes that all your graphical objects are in "Output" cells.


11

The main point is that Jupyter is a flat structure, but the Notebook is a nested structure. It took me a long time to fully solve this problem. Thanks for @b3m2a1 's advice, text problems has reduced. Now there still some problem: Picture rendering has incomprehensible edges More issues not found, put test files at GalAster/JupyterConvert if find any. ...


9

This nb2ipynb function takes the notebook filename as input and it returns a jupyter notebook compatible with JWLS. nb2ipynb = Module[{ cellF = { "cell_type" -> "code", "execution_count" -> 1, "metadata" -> <||>, "outputs" -> {<|"name" -> "stdout", "output_type" -> "stream", "...


9

You could try adding ImagePadding and AxesEdge to prevent the axes from jumping around. f = Table[ Plot3D[(1 + Sin[2 π t]) E^(-(x - Sin[2 π t])^2 - (y - Cos[2 π t])^2), {x, -2, 2}, {y, -2, 2}, PlotLabel -> t, PlotRange -> All, ViewPoint -> {-2, -2, 1}, ImagePadding -> {{40, 0}, {0, 0}}, AxesEdge -> {{-1, 1}...


8

No, there is not, and yes, this is annoying, especially since the header is not really needed for this format (the precise format variant is marked using the initial character). You can do something like StringTrim[ ExportString[CycleGraph[5], "Graph6"], ">>graph6<<" ] then export (or copy) the resulting string. Side note: Better graph6/...


7

ImageAlign should probably be at least part of the solution: img = Import["https://i.stack.imgur.com/pc6ul.png"]; {xdim, ydim} = ImageDimensions[img]; images = Flatten@ImagePartition[img, {xdim/4, ydim/4}]; aligned = ImageAlign[images]; ListAnimate[aligned] Here is an attempt to make it more robust and to prevent it from clipping parts of the figure off at ...


7

I'd just make a set of frames and export those: frames = Table[ Show[ ParametricPlot[Evaluate[{x[t], y[t]} /. ss1], {t, tmax - 1, tmax}, PlotStyle -> {Thick, Green}, PlotRange -> 1.4, AspectRatio -> 1, PerformanceGoal -> "Quality"], Graphics[{PointSize[.03], Red, Point@{x[tmax], y[tmax]} /. ss1}, PlotRange -> 1....


6

The link was updated after request! For the convenience I have reuploaded the main file to the Google Drive: https://drive.google.com/open?id=1k1-SkH0mrA__gF68JThGyKtsMkVj3Neg In Windows the full paths to the MathPSFrag Options are recommended (see). MathPSFrag is recommended to use with CustomTicks package, that copy of which is also uploaded to the ...


6

It's not clear how XML can be converted to JSON in a general way, because how would one deal with attributes? You happen not to have attributes in your XML, but that's just a special case. Luckily, Mathematica is a great language to write ad hoc parsers in. convert[XMLObject["Document"][{}, content_, {}]] := convert[content] convert[XMLElement[tagName_, _, ...


6

Online services, such as the one referenced in the question, require the image to be in one of the standard web formats (PNG, JPEG, etc.) First you must export the graphics into one of these image formats. This gives you a string of bytes (a file). Base64 is a way to encode a string of arbitrary bytes into a string of ASCII characters. As Kuba mentions, ...


6

You can use Null for the empty elements e.g. Export["foo.xlsx", listA~Join~{Null, Null}~Join~listB]


6

I think you probably want to use NSolve instead of Reduce. roots = x /. NSolve[x Tan[x] == 5 && 0 <= x <= 100, x] Export["outfile.xls", roots] This will produce a column of 32 roots, which I think is what you want.


6

Actually, the conversion of Sequence into the List can be done easy: a=ToRules@Reduce[x Tan[x] == 5 && 0 <= x <= 100, x]; b=x /. List[a]; Export["file.xlsx", b] The Export gives you an Excel file with the desired column of numbers


5

This has been a long-term annoyance when exporting graphics from Mathematica. The root cause is that non-Graphics notebook objects are exported in the "Printout" environment, which downscales to 80% by default. It is discussed here and in the MaTeX tutorial titled "Preparing Figures to Size". The symptom If expr is not Graphics or Graphics3D, then Export[...


5

Export["a.txt", Map[OutputForm, a, {2}], "Table", "FieldSeperators" -> ""] OutputForm can be replaced by ToString.


5

Actually, this is strange that such possibility is not a built-in function. Let's say, we have a list of 150 strings like this: tbl = Table[{a, ToString@(a RandomReal[{-2, 2}])}, {a, 1, 150}]; My workaround for pages formation is following: spp = 64; (*the desired number of strings per page, depending on content size and page size*) tmp = Table[ tbl[[...


5

It appears that Mathematica only exports surface data to VTK (i.e., Polygons) and the format that it exports in an old format and not the new XML format. The following bullet point from the Background & Context section of the VTK documentation describes the limitation. Stores a single 3D object as a collection of line, point, and polygon primitives ...


4

I faced with the same issue. Using Mathematica's function ExportString[…, "ExpressionJSON"] I attempted to export the whole tree of graphical functions and wrote a parser in JS. It was uploaded to GitHub, here is the link. There is a primitive construction with a lot of "switch-case" statements. Each of them implements self function like changing the color ...


4

You can use PreviousCell for this purpose. For example: Export["code.pdf", NotebookRead[PreviousCell[]]] should grab the cell contents of the previous cell, and save it to your file.


4

Regarding the commented example (it is wise to update your post with such things, for future reference) one would do something like the following: A=3; out[A_,function_]:=outfunc[A,function]; (*where outfunc[arg, argfunc] is the function based on arg and argfunc one would like to export*) outexporter[A_,function_,driveletter_]:=outexporter[A,function,...


4

You may use StringTemplate. For values of some parameter. tFilename = StringTemplate["AValueAt`1`.gif"]; tFilename /@ {1, 2, 2.5, 3} {"AValueAt1.gif", "AValueAt2.gif", "AValueAt2.5.gif", "AValueAt3.gif"} You can also include the plot result name. tFilename2 = StringTemplate["Step`1`_AValueAt`2`.gif"]; tFilename2 @@@ {{"One", 1}, {"Two", 2.5}, {"Three", ...


4

I've not been involved with XML lately, but I used to (re)define XMLObject and XMLElement to process an XML structure. It's usually received lukewarm appreciation on this site, but it seems like the sort of expression-rewriting Mathematica was built for. And in this case, it's easy: json = Block[ { XMLObject = Function[{#2} &], , XMLElement = #1 ...


4

What happens if you go to Edit | Preferences | Appearance | Graphics and crank the slider for "Antialiasing Quality" up to highest quality? Also, you might want to consider trying the antialias functions given here and here. Those posts might contain additional helpful information about the topic. When you do this, it's easy to get something like this


4

I want to get something like this Well, I think it is better to export the data as is, i.e. without chopping it. Let the client who reads the file later on decide if they need less accuracy. So you could save it as data = Table[Flatten@{x, u[x] /. s, v[x] /. s}, {x, 0, 1, 0.1}]; Export["data.txt", data, "TSV"] This gives 0. 1. 1. 0.1 1....


4

Row formats input list "arranged in a row, potentially extending over several lines". To prevent line breaks, you can wrap Row[...] with Style using the option LineBreakWithin -> False: ClearAll[fun2]; fun2[n_, k_] := With[{t = Tuples[{0, 1}, n], r = {0 -> "\[UpArrow]", 1 -> "\[DownArrow]"}}, Column[Style[Row[#, " "], LineBreakWithin -> False]...


4

Based on the answer to this question, you can wrap the plots in a Cell and specify the PageWidth there: SetOptions[$FrontEndSession, PrintingStyleEnvironment -> "Working"] ImportString[ ExportString[ Cell[ BoxData@ ToBoxes@Row@ Table[ListPlot[RandomReal[{0, 1}, {5, 3}], ImageSize -> 300], 3], PageWidth -> Infinity ], "PDF" ...


4

Add Bookmarks: anim = Animate[Plot[Sin[x + a], {x, 0, 10}], {a, 0, 5}, Bookmarks -> {"start" :> {a = 0}, "stop" :> {a = 5}}]; Export["animation.gif", anim]


4

Here is an approach that address the core of your request First strip the values from the Association and group them with Partition. z1 = Values[coord] // Partition[#, 3] & ; Now create a file variable theFile = File["exportFile.txt"]; Export as follows (using "Table" argument to Export Export[theFile, z1, "Table"]; This ...


4

If this is really the structure, maybe you could use a dataset instead? pdata = Partition[coord/. h_[i_Integer] -> h, 3] ds = Dataset[Association @@@ pdata] Indexes are supplied automatically. E.g., ds[[1]]


Only top voted, non community-wiki answers of a minimum length are eligible