Your own options for Plot functions

In many cases plotting can be made easier by creating your own plotting functions which make use of the many built-in functions in Mathematica. There are times when you would like to be able to use DisplayFunction-> Identity but find that it conflicts with the way options work. Here is a solution for that difficulty. First we load the Graphics packages so we can use PieChart.

<<Graphics`

Suppose you want to create a sequence of pie-charts illustrating quarterly sales. If we use the following definition there is no way to suppress the output and so putting these plots in an array produces unwanted plots.

yearData[data_]:=
PieChart[data,PieLabels -> {"1stQ Sales","2ndQSales","3rdQ Sales","4thQ Sales"}]

This gives a pie-chart but does not work if we use DisplayFunction as an option.

yearData[{.2,3,.25,.25}]

yearData[{.2,3,.25,.25},DisplayFunction -> Identity]

A solution

Although it is possible to filter our options to allow more flexibility it is often easier to introduce an option of our own if this is the only option we anticipate using with our function. In this case we call the option ShowPlot and allow it to take two values, True and False. We then use an If statement to determine the behavior of our function.

yearData[data_,opts___]:=Module[{shwplt},
shwplt = ShowPlot/.{opts}/.ShowPlot -> True;
If[shwplt === True,
PieChart[data,PieLabels -> {"1stQ Sales","2ndQSales","3rdQ Sales","4thQ Sales"}],
PieChart[data,PieLabels -> {"1stQ Sales","2ndQSales","3rdQ Sales","4thQ Sales"},DisplayFunction -> Identity]]
]

yearData[{.2,3,.25,.25}]

Here we suppress the display of the plot using ShowPlot -> False.

yearData[{.2,3,.35,.15},ShowPlot-> False]

This allows us to create an Array of pie-charts without seeing the individual plots.

Show[GraphicsArray[{{yearData[{.2,.3,.32,.18},ShowPlot-> False],yearData[{.4,.3,.2,.1},ShowPlot-> False]}}],ImageSize -> 360]