# Tag Info

53

The main change since that time seems to be that the modern way of using options is associated with OptionsPattern[] - OptionValue commands. A typical way of defining a function would be: Options[f] = { FirstOption -> 1, SecondOption ->2 } f[x_,y_,opts:OptionsPattern[]]:= Print[{x,y,OptionValue[FirstOption],OptionValue[SecondOption]}] ...

52

The documentation is wrong. It should have been fixed, but AbsoluteOptions does not work with ViewMatrix (on all platforms). M- introduced interactive 3D graphics since V6, and after that getting values through AbsoluteOptions (which is an old function) becomes very tricky since the Kernel (who evaluates the option) cannot fully know what is happening on ...

37

One thing you can do is look for options which appear in a function's Options but do not have a ::usage message. Of course, some of the results actually are documented in the help, they just don't have a usage message. Here's a function to do it: undoc[x_Symbol]:=Select[Options[x],!StringQ@MessageName[Evaluate@First@#,"usage"]&]; undoc[_] = {}; (* e.g. ...

33

For this purpose, I wrote a small Symbol Information Palette. This palette let's you quickly look up usages, options and attributes of symbols and was tested on Mac OSX and Linux. Installation The source code is hosted on my GitHub site but to preview or install the palette you only have to evaluate this: Get["http://goo.gl/QPywk"] The link is just ...

28

It got a bit out of hand, but here's a way to construct a ViewMatrix pair from the triple ViewVector, ViewAngle, and ViewVertical. The left figure is the Graphics3D object using ViewVector, ViewAngle, and ViewVertical and the right is the one using ViewMatrix. If you rotate the left figure or scale it (by dragging the figure while keeping Alt depressed), the ...

27

Here is a practical example from a StackOverflow question. I hope that it gives a good overview of the basic methods. Question What would be the best way to make a function out of the below code ? It would take a dataList as well as some graphical options (such as colors) as arguments and return a customized tabular representation as shown ...

26

1. Discovery may be aided by Trace and related tools. I recommend WReach's traceView functions. 2. Simple observation and experimentation. Simple does not imply easy. As an example, to find the answer to "Can the frame border on a BarChart Legend be removed?", I used: BarChart[{{1, 2, 3}}, ChartLegends -> {"A", "B", "C"}] // Trace // InputForm ...

25

One way would be to use ColorConvert to convert the RGB or Hue values to gray scale. Here's an example: Plot[{Sin[x], Cos[x], Exp[-x^2], Sinc[π x]}, {x, 0, π}] /. x : _RGBColor | _Hue | _CMYKColor :> ColorConvert[x, "Grayscale"] For 2D plots that accept a ColorFunction, you can simply use GrayLevel to get the plot in grayscale as: DensityPlot[ ...

25

You could plot the curve twice, with two different styles: Plot[{Sin[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[Thickness[0.03], White], Black}] Changing the background to gray: Plot[{Sin[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[Thickness[0.03], White], Black}, Background -> Gray]

24

I doubt you can find a chart for all options, but take a look at this: For this and other insights two courses by Yu-Sung are a must (there are notebooks and videos there): Graphics Language Quick Start Visualization: Advanced 3D Graphics The above chart is from the 1st one. The one @Kuba links in the comment to your question is from the 2nd - I ...

21

I think you can actually see (most of) what Mathematica is doing by using Trace[..., TraceInternal -> True]. For example, Select[Flatten[ Trace[NDSolve[y'[x] == x && y[0] == 0, y, {x, 0, 6}], TraceInternal -> True]], ! FreeQ[#, Method | NDSolveMethodData] &] shows the DE was evaluated using NDSolveLSODA and Newton's method. (I ...

21

I find SetSystemOptions["PackedArrayOptions" -> {"UnpackMessage" -> True}] to be useful: it emits a message when a packed array is unpacked. This may happen automatically, sometimes slowing down things greatly. This is useful in situations like this or this. One way one would find out that such an option exists is "PackedArrayOptions" /. ...

20

Mathematica has to be able to tell that the default arguments can't be rules. So, for some special cases, you could do Options[f] = {"g" -> Identity}; f[x_, y_Integer: 2, z_Integer: 3, OptionsPattern[]]:= OptionValue["g"][x + y + z] Testing: f[1, 2, 3, "g" -> (#^2 &)] 36 f[1] 6 f[1, "g" -> (#^2 &)] 36

20

Here is another approach, based on Filling option : Plot[{Sin[x] - 0.02, Sin[x], Sin[x] + 0.02}, {x, 0, 2 Pi}, PlotStyle -> {Gray, Black, Gray}, Filling -> {1 -> {{3}, Yellow}}] One problem may appear here, namely if a given function has a big absolute value of the derivative, then the strip becomes too thin. We can avoid this by ...

19

Edit: better answer below. I voted for Rojo's answer. If for some reason you cannot be that specific about your arguments you might use the converse: nr = Except[_?OptionQ]; f[x_, y : nr : 2, z : nr : 3, OptionsPattern[]] := OptionValue["g"][x + y + z] If for some further reason you need the optional arguments to be rules themselves, you could filter ...

19

A guess My guess is that you have just run into the details of OptionValue implementation, which are also responsible for its "magical" behavior. OptionValue has to somehow know which function it is in, and tracing the execution of f4[] shows that apparently the following expansion is happening before any evaluation is attempted for the r.h.s.: ...

17

John Fultz posted an answer which had an undocumented option. CellPrint[{ Cell["Click to open the section", "Section", System`WholeCellGroupOpener -> True], TextCell["Some text"]}] This produces a section cell that if you click anywhere on it will open and close the whole section.

15

Here is another method that I learned through reading Inside the Mathematica Pattern Matcher: Options[f] = {"g" -> Identity}; f[x_, Shortest[y_: 2, 1], Shortest[z_: 3, 2], OptionsPattern[] ] := OptionValue["g"][x + y + z] From the documentation for Shortest: Shortest[p, pri] is given priority pri to be the shortest sequence. Matches for ...

15

A bit late-to-the-party post, and complementary to the other solutions. Several answers addressed the question quite well IMO. I had my shot on a similar one here, with a solution similar to the one by @Mr.Wizard. But now I just want to stress one subtle point missed by other answers: using OptionQ will leak evaluation for functions which are HoldAll and ...

15

Short answer: You supply a pure function to an option when you want to override the built-in options. In this case, "Diamond" and 0.2 resolve to certain functions or are used as values in certain functions internally which is then used for the respective option. The short names are merely a convenient way for you to remember and enter the option. Longer ...

15

A minor tweak to Markus' method, you may find utility in CapForm: Table[ Plot[{Sin[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[AbsoluteThickness[15], CapForm[c], White], Directive[AbsoluteThickness[7], Blue]}, ImageSize -> 400, PlotRangePadding -> 0.2, Frame -> True, Prolog -> ...

15

The problem we encounter here is an instance of rather unexpected limitations of equation solving functionality (i.e. Modulus option in Reduce), e.g. this question : Strange behaviour of Reduce for Mod[x,1] provides another example which has been fixed in the newest version (9.0) of Mathematica. Since Modulus unexpectedly doesn't work here we can take ...

14

All of the polynomial functions, have an option Modulus which allows you to specify an integer field, like $\mathbb{Z}_5$. In particular, Factor works on your example polynomial Factor[x^2+4, Modulus -> 5] (* (1 + x) (4 + x) *) Additionally, IrreduciblePolynomialQ works to determine irreducibility of $x^2+2$, as follows IrreduciblePolynomialQ[x^2 + ...

14

There are two problems I see with this code. The first one, and the one which gives you immediate problem you reported, is that, as it looks, short (magical) form of OptionValue does not work with SubValues - based definitions. So, you should replace OptionValue["type"] with OptionValue[{opts}, "type"] Or, if you wish to associate the option with pump ...

14

AbsoluteOptions is known as very buggy function and the bug in determining the true PlotRange has very long history... You could try my Ticks-based workaround for getting the complete PlotRange (with PlotRangePadding added): completePlotRange[plot:(_Graphics|_Graphics3D|_Graph)] := Last@ Last@Reap[ Rasterize[ Show[plot, Axes -> True, ...

13

The answer given by @halirutan lead me to a thought that we can use Pane[..] as elements of Grid[...] to obtain desired behavior. Panel[...] can work too, but it introduces extra boundaries. Grid@Partition[MapThread[Pane[Graphics[Rectangle[], ImageSize -> #1], ImageSize -> {60, 60}, Alignment -> #2] &,{{20, 30, 40, 50}, {{1, -1}, {-1, -1}, ...

13

This question is somewhat subjective, but here's my take on it: The reason the precise methods are mentioned in papers is to make results reproducible. One has to draw a line when it comes to describing methods. Will you mention what method you used to add or multiply numbers on a computer? What if the numbers are huge and you used FFT-accelerated ...

13

You can define your own function for FrameTicks : ticks[min_, max_] := {#, NumberForm[#, 20]} & /@ N[FindDivisions[{min, max}, 5]] ListPlot[{RandomReal[#] + 10^4, RandomReal[#]} & /@ (Range[100] 10^-10), Frame -> True, FrameTicks -> {{Automatic, None}, {ticks, None}}] Just choose your own preferred presentation format of the ...

13

It seems that the handling of the Alignment option is not consistent for all functions using it. Panel for instance seems to support numeric values for this option Manipulate[ Panel["\[Times]", ImageSize -> {100, 50}, Alignment -> {x, y}], {x, -1, 1}, {y, -1, 1} ] while with Grid this is not supported. Knowing this, you could check functions ...

13

Interactive illustration of the most fundamental properties: Manipulate[ Column[{ Overlay[{ Framed[Graphics[{ LightYellow, Rectangle[{-plotRangePadding - plotRange, -plotRangePadding - plotRange}, {plotRangePadding + plotRange, plotRangePadding + plotRange}], LightGreen, ...

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