Hot answers tagged

8

In general, I using the following strategy: Using a varible $MethodValues to store all the possible method value. Using If[] and Return[$Failed] to check the validness of method value that user given, which can make the code more robust. Using Switch[]/Which[] to deal with each case. Options[saveData] = {Method -> Automatic}; $MethodValues = ...


7

To whom it may concern, a workaround: path = FileNameJoin[{$HomeDirectory, "Desktop", "testWorking.nb"}]; nb = Notebook[{}, Saveable -> False, NotebookEventActions -> {{"MenuCommand", "Save"} :> {}} (*the fix*) ]; Export[path, nb, "NB"]


7

Normally this would be comment. but I post it here so there will be an answer. There is nothing wrong with the way you implementing your function. Your code is robust, simple, and efficient and IMO follows good Mathematica functional programming style.


6

Introduction What are good (robust?, simple?, efficient?) patterns for doing this kind of code-switching? This answer outlines a development strategy that can produce robust and extensible method option handling. Conceptually and development-wise, it is not that simple, but it has been successfully applied in large software projects with complicated ...


4

This doesn't allow the extraction and reconstruction of the unknown ColorFunction, but it does allow to override it with an exact duplicate that is transparent, plt1 = Plot[Sin[x], {x, 0, 2 Pi}, ColorFunction -> (#^2 &), ImageSize -> 300]; plt2 = Plot[Sin[x], {x, 0, 2 Pi}, ColorFunction -> (Hue[#^2] &), ImageSize -> 300]; plt3 = ...


4

There is a straightforward way to set CellMargins to be zero: DialogInput[ DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 8], CellMargins -> 0]}]] Instead of ImageMargins we can rely on CellFrameMargins: DialogInput[ DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 8, ...


3

This is one aspect of a classic problem: Plot is HoldAll. So, moreProp is not being evaluated. I think the most effective way to work around this is to use With (cf. this question) to inject the values into Plot, e.g. newPlot[func_, range_, prop___] := With[{mp = moreProp}, Plot[func, range, prop, mp]] Then, it works: Alternatively, you can use ...


3

I think you just need ReplaceAll A method to strip off all those rules together (in the example above leaving me with H[a, b, c]). hh /. { _Rule -> Sequence[]} (* H[a, b, c] *) A method to exchange one specific rule (identified by lhs) of the form lhs->rhs by some other expression of rhs. hh /. {(f -> _) -> (f -> x)} (* H[a, b, c, d -> e, ...


3

I gave up looking for neat solution. Here's brute force. Since the bottom CellMargins are not respected then let's not use any! :) We can use Pane and its ImageMargins to take control over padding. DialogInput[ DynamicModule[{}, Pane[RandomImage[], ImageMargins -> 8], Initialization :> (SetOptions[EvaluationCell[], CellMargins -> ...


2

InitializationGroup vs group of InitializationCells If you create a new cell in an InitializationGroup it will automatically become an InitializationCell. For the group of InitializationCells you will get a default one, which you can turn into another InitializationCell or not. A set of InitializationCells vs one InitializationCell. I can't find any ...


2

It really expects that you have some buttons along the bottom. DialogInput[Column[{Pane @ RandomImage[], Button["OK", DialogReturn[0]]}]] but you can do it this way DialogInput[Column[{Pane @ RandomImage[], ""}]] Update I Think it looks better with the bottom margin a bit larger than the top, but if you are being picky about equal margins, try ...


2

I don't think it's possible to extract such information from an already evaluated plot. Plot returns a Graphics object and very little meta-information is stored. We can see this by inspecting with InputForm. InputForm[Plot[1, {x, 0, 1}, ColorFunction -> Hue, PlotPoints -> 2]] Graphics[{GraphicsComplex[{{1.*^-6, 1.}, {0.999999, 1.}, {0.5, 1.}}, ...


1

According to the Documentation, you should set CellLabelAutoDelete -> False for making cell labels permanent: Create a notebook with the setting CellLabelAutoDelete -> False: nb = CreateDocument[{ExpressionCell[Defer[1 + 1], "Input"], ExpressionCell[Defer[2 + 2], "Input"]}, CellLabelAutoDelete -> False] When inputs are evaluated, ...



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