# GridLinesStyle not working with SetOptions

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]


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

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.

• 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 – José Antonio Díaz Navas Nov 24 '17 at 15:46

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

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


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

And here's something related:

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]


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]


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]


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.