I'm looking for a way to create a variable that I can use to hold all of the graphics directives for, say, a plot command. For example, I have 8 plots with variations on the following:

Plot[{Im[eppar[400*10^12, t, 0.1]],
      Im[eppar[400*10^12, t, 0.2]], 
      Im[eppar[400*10^12, t, 0.5]], 
      Im[eppar[400*10^12, t, 0.8]]
     }, {t, tlow, thigh}, (**directives**)]

There's a fairly long list of directives I'm using for the plots, and I'd like to avoid having to modify 8 long, complicated expressions every time I want to change anything. Does anybody know of a solution to this? It would make my code much cleaner.

  • $\begingroup$ You can use With like in here. $\endgroup$
    – Kuba
    Jul 30, 2013 at 17:33
  • $\begingroup$ Can you give us a clearer idea what you have in mind when you say "avoid having to modify 8 long, complicated expressions every time I want to change anything"? And I think we would like to see the "8 long, complicated expressions" and definition or eppar so we can work with your code. $\endgroup$
    – m_goldberg
    Jul 30, 2013 at 17:59
  • $\begingroup$ I think you may simply be looking for Directive. $\endgroup$
    – C. E.
    Jul 30, 2013 at 18:22
  • $\begingroup$ Closely related: (20718) (setSpec in my second answer is directly applicable.) $\endgroup$
    – Mr.Wizard
    Jul 30, 2013 at 20:12
  • 1
    $\begingroup$ @Mr.Wizard Guys, this is not a duplicate of that question (somehow my comment was deleted). That question was about how options are passed to HoldAll functions, but the question asked here is not about that technicality. It is much closer (may be a dupe) to this one. I hope I won't have to repeat this comment a third time (i.e this one won't get deleted). $\endgroup$ Jul 30, 2013 at 21:35

2 Answers 2


Here is another way using Evaluate:

ops1 = {Filling -> {1 -> {2}}, PlotStyle -> {Red, Green}, Frame -> True};

Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10}
      , Evaluate@ops1
      , PlotLabel -> Style["Using Evaluate", 20]

enter image description here


On Leonid's valued opinion that the Close was inappropriate I have reopened this question.

By my interpretation this does what is requested:

SetAttributes[setSpec, HoldAllComplete]

setSpec[s_Symbol, spec__] := s /: h_[pre__, s, post___] := h[pre, spec, post]

The usage is:

 Filling -> {1 -> {2}},
 PlotStyle -> {Red, Green},
 Frame -> True


Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10}, ops1]

enter image description here

Because Plot handles both Plot[. . ., option1, option2, . . .] and Plot[. . ., {option1, option2, . . .}] you can use either form in setSpec.

setSpec can also be configured to apply to only certain heads, e.g.:

SetAttributes[setSpecFor, HoldAllComplete]

setSpecFor[head_Symbol, s_Symbol, spec__] := s /: head[pre__, s, post___] := head[pre, spec, post]

And usage would be: setSpecFor[Plot, ops1, (* options *)]

This allows you to use the same name (Symbol) for separate options for different plot types.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.