5

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.

Sennin
  • 117
  • 5

2 Answers2

4

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.

Nasser
  • 143,286
  • 11
  • 154
  • 359
2

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:

Kuba
  • 136,707
  • 13
  • 279
  • 740