2
$\begingroup$

I need to use almost the same options for several graphics, and would like to simplify the code which is becoming pretty large. The example below should work, but it doesn't for a reason I don't see.

GraphOptions[p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_] := Sequence[
    PerformanceGoal -> "Quality",
    PlotRange -> {{p1, p2}, {p3, p4}},
    PlotRangeClipping -> True,
    AspectRatio -> 1,
    Frame -> True,
    Axes -> True,
    AxesOrigin -> {0, p5},
    AxesStyle -> GrayLevel[0.6],
    LabelStyle -> Directive[FontSize -> 12],
    FrameLabel -> {
        Style[p6, FontSize -> 14],
        Style[p7, FontSize -> 14],
        Style[p8, Bold, FontSize -> 16, FontFamily -> "Helvetica"]
    },
    RotateLabel -> False,
    GridLines -> Automatic,
    GridLinesStyle -> Directive[GrayLevel[0.7], Dashed],
    ImageSize -> {512, 512}
]

Plot[t^2 - t, {t, -1, 1},
    GraphOptions[-4, 4, 0, 4, 1, u, v, "A simple title"]
]

Currently, Mathematica complains

Options expected (instead of GraphOptions...). An option must be a rule or a list of rules.

So what's wrong with this code ? I tried with { } instead of Sequence[ ], but I'm getting the same error message.

This is surrely pretty basic, but I don't see my mistake.

$\endgroup$
7
  • 6
    $\begingroup$ Plot is HoldAll, try with Evaluate@GraphOptions. $\endgroup$
    – Kuba
    Dec 18, 2016 at 19:54
  • $\begingroup$ Why this ? Is there a better way to define my GraphOptions function ? $\endgroup$
    – Cham
    Dec 18, 2016 at 19:55
  • 3
    $\begingroup$ Perhaps defining your own PlotTheme is the way to go. $\endgroup$
    – Michael E2
    Dec 18, 2016 at 19:56
  • $\begingroup$ Why do you object to the need for prefixing your call to GraphOptions with Evaluate @? $\endgroup$
    – m_goldberg
    Dec 19, 2016 at 1:30
  • $\begingroup$ @m_goldberg, I do not object to use it. I was wondering if my settup could be done in another way (something more "natural" I'm unaware of ?). Currently, the Evaluate[ ] works very well. $\endgroup$
    – Cham
    Dec 19, 2016 at 3:52

0