5
$\begingroup$

On all the plots of a notebook I have to put a vertical line at the same place. I thus use the GridLines option for Plot along with the option GridLinesStyle. To get it done easily I use the function SetOption for Plot:

SetOptions[Plot,GridLines->{{1},{}},GridLinesStyle->Red]
Plot[x,{x, 0, 2}]
Plot[x,{x, 0, 2},GridLinesStyle->Red]

enter image description here

The style has not been applied to the GridLine in the first plot

enter image description here

It worked here

Am I doing something wrong, or is it just that GridLinesStyle does not work with SetOptions for some reason? I do apologize if this question has already been asked but I could not find any information about this issue.

$\endgroup$
1
  • $\begingroup$ In the second plot GridLinesStyle overrides previous settings . What I am also wondering why the first case does not work... However, it works with PlotStyle $\endgroup$ Nov 24, 2017 at 15:46

2 Answers 2

2
$\begingroup$

Certain options can be overwritten by PlotTheme so we can skip it:

Plot[x, {x, 0, 2}, PlotTheme -> None]

enter image description here

Would be nice to have more official/documented investigation tools but meanwhile you can search around to learn more:

And here's something related:

$\endgroup$
4
$\begingroup$

This might be a bug, might be worth reporting it. But here is a work around. Assign the output of SetOptions to global variable, and then use that in all your plots. If you want to add options locally, you can append to them. Like this

globalPlotOptions=SetOptions[Plot,GridLines->{{1},{}},GridLinesStyle->Red];
p=Plot[x,{x,0,2},Evaluate@globalPlotOptions]

Mathematica graphics

If you want to add options for some plot then make sure to put those local options before adding the global ones

globalPlotOptions=SetOptions[Plot,GridLines->{{1},{}},GridLinesStyle->Red];
p=Plot[x,{x,0,2},PlotStyle->Dashed,Evaluate@globalPlotOptions]

Mathematica graphics

i.e do not do this below, as it will have no effect:

globalPlotOptions=SetOptions[Plot,GridLines->{{1},{}},GridLinesStyle->Red];
p=Plot[x,{x,0,2},Evaluate@globalPlotOptions,PlotStyle->Dashed]

Mathematica graphics

Since order makes difference. This means you just have to add Evaluate@globalPlotOptions each time to all the plot commands. This is work around until one find why this option is not making any effect or if it is a bug, until it is fixed.

$\endgroup$

Your Answer

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

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